SyntheticControlMethods
SyntheticControlMethods copied to clipboard
When I run “sc = Synth(data,……n_optim=100)”, I get the error "ValueError: 'x0' must only have one dimension."
run code below , get the error "ValueError: 'x0' must only have one dimension."
# Fit synthetic control
sc = Synth(data, "gdp", "country", "year", 1990, "West Germany", n_optim=100)
maybe optimize.py should delete "size=1"?
else:
#Dirichlet distribution returns a valid pmf over n_covariates states
v_0 = self.original_data.rng.dirichlet(np.ones(data.n_covariates), size=1)
if pen == "auto":
#if pen =="auto", we have an additional parameter to optimize over, so we append it
v_0 = np.append(v_0, self.original_data.rng.lognormal(1.5, 1, size=1)) #Still experimenting with what distribution is appropriate
I successfully ran it after removing the “size = 1” parameter
The error was shown again even when remove the paramete of "size=1". I also made changes to the optmize function as below:
res = minimize(self.total_loss, np.asanyarray(v_0).flatten(), args=(args), method='L-BFGS-B', bounds=bnds, options={'gtol': 1e-8,'disp':3, 'iprint':3})
to make sure the matrix 'v_0' in the iterations follows dimension requirments.