Is it possible to implement the following problem in mystic?
The problem minimizes a sum of squares between two (10000 by 40) matrices: Σ(X-A)^2 where X is a concatenation of four matrices (10000 by 10) and each segment is weighted (W) individually. There is also a constraint where the sum of the weights must equal 1 i.e. (W1 + W2 + W3 + W4 = 1). I'm currently using the SLSQP method in scipy optimize to get the optimal weight values but I want to determine if mystic can improve its performance. I also need to retrieve the final weight values.
from scipy.optimize import minimize
import numpy
def objective(W,X1,X2,X3,X4,A):
W1=W[0]
W2=W[1]
W3=W[2]
W4=W[3]
X=numpy.vstack((W1*X1,W2*X2,W3*X3,W4*X4))
return numpy.sum((X-A)**2)
def constraint1(W):
W1=W[0]
W2=W[1]
W3=W[2]
W4=W[3]
return W1+W2+W3+W4-1
x0=[[0.25,0.25,0.25,0.25]]
cons = {'type': 'eq', 'fun':constraint1}
#Random data only used for purposes of example
segment_1 = numpy.random.rand(10000, 10)
segment_2 = numpy.random.rand(10000, 10)
segment_3 = numpy.random.rand(10000, 10)
segment_4 = numpy.random.rand(10000, 10)
A = numpy.random.rand(10000, 40)
sol=minimize(objective,x0[0],args=(segment_1,segment_2,segment_3,segment_4,A),method='SLSQP',constraints=cons)
print(sol.x)