1

I am trying to solve an optimization problem using CVXPY library. My code runs properly on a dummy dataset but crashes when I key in the actual dataset. The error I got is

Segmentation fault      (core dumped)

I tried to search for the solution on https://github.com/cvxgrp/cvxpy/issues/69, https://github.com/cvxgrp/cvxpy/issues/984 but to no avail

My code sample looks like

import cvxpy as cp
import numpy as np
from numpy import linalg as LA   

X_source = np.load("seen_class_vgg16_features.npy")
Y_source = np.load("seen_class_labels.npy")

#Shuffling the two feature matrices along with their corresponding labels

from sklearn.utils import shuffle 
Xs, ys = shuffle(X_source, Y_source, random_state=0)

#Now loading all classes attributes

all_classes_attributes = np.load("all_classes_attributes.npy")

ys =  [int(i) for i in ys]
ys = np.asarray(ys)

Ys = []

for i in ys:
    Ys.append(all_classes_attributes[i-1])

Ys = np.asarray(Ys)

# Define and solve the CVXPY problem.
Ds = cp.Variable(shape=(312,4096))

def objective_fn(Xs, Ys, Ds, lamda1, lamda2):
    return (cp.square(cp.norm(Xs-Ys*Ds,'fro')) + lamda1*cp.square(cp.norm(Ds,'fro')) + lamda2*(cp.square(cp.norm(Ds,'fro')) - 1))

lamda1 = cp.Parameter(nonneg=True)
lamda2 = cp.Parameter(nonneg=True)

Ds_values = []

lamda1_values = []
lamda2_values = []

problem = cp.Problem(cp.Minimize(objective_fn(Xs,Ys,Ds,lamda1,lamda2)))

lambd1_values = np.logspace(-2, 3, 2)
lambd2_values = np.logspace(-2, 3, 2)

for lam1 in lambd1_values:
    for lam2 in lambd2_values:
        lamda1.value = lam1
        lamda2.value = lam2
        problem.solve(qcp=True, verbose=True)
        print("Optimal value of Ds = ",Ds.value)
        lamda1_values.append(lam1)
        lamda2_values.append(lam2)
        Ds_values.append(Ds.value)

the irony is that on a smaller but dummy dataset, the code runs flawlessly.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Upendra01
  • 344
  • 3
  • 5
  • 15
  • Where exactly? Please post the complete error trace (and be sure to remove any code that may come *after* the error). – desertnaut May 29 '20 at 19:39
  • Yikes! Can you first make sure you're using the latest version of CVXPY? If you are, please open an issue in our Github repository (https://github.com/cvxgrp/cvxpy/issues) (with code to reproduce the issue and the complete stack trace), and we'll look at it as soon we can. – Akshay Agrawal May 30 '20 at 17:34

0 Answers0