@@ -45,47 +45,53 @@ def apply(self, objective : Equation, arguments : dict = None):
4545 # self_args, subop_args = self.parse_suboperator_args(arguments = arguments)
4646
4747 assert objective .weights_internal_evald , 'Trying to calculate final weights before evaluating intermeidate ones (no sparsity).'
48- target = objective .structure [objective .target_idx ]
49-
50- target_vals = target .evaluate (False )
51- features_vals = []
52- nonzero_features_indexes = []
53- for i in range (len (objective .structure )):
54- if i == objective .target_idx :
55- continue
56- idx = i if i < objective .target_idx else i - 1
57- if objective .weights_internal [idx ] != 0 :
58- features_vals .append (objective .structure [i ].evaluate (False ))
59- nonzero_features_indexes .append (idx )
60-
61- if len (features_vals ) == 0 :
62- objective .weights_final = np .zeros (len (objective .structure ))
63- else :
64- features = features_vals [0 ]
65- if len (features_vals ) > 1 :
66- for i in range (1 , len (features_vals )):
67- features = np .vstack ([features , features_vals [i ]])
68- features = np .vstack ([features , np .ones (features_vals [0 ].shape )]) # Добавляем константную фичу
69- features = np .transpose (features )
70- estimator = LinearRegression (copy_X = True , fit_intercept = False , n_jobs = - 1 ,
71- positive = False , tol = 0.0001 )
72- # estimator = LinearRegression(fit_intercept=False)
73- if features .ndim == 1 :
74- features = features .reshape (- 1 , 1 )
75- try :
76- self .g_fun_vals = global_var .grid_cache .g_func [global_var .grid_cache .g_func != 0 ]
77- except AttributeError :
78- self .g_fun_vals = None
79- estimator .fit (features , target_vals , sample_weight = self .g_fun_vals )
80-
81- valueable_weights = estimator .coef_
82- weights = np .zeros (len (objective .structure ))
83- for weight_idx in range (len (weights )- 1 ):
84- if weight_idx in nonzero_features_indexes :
85- weights [weight_idx ] = valueable_weights [nonzero_features_indexes .index (weight_idx )]
86- weights [- 1 ] = valueable_weights [- 1 ]
87- objective .weights_final = weights
88- objective .weights_final_evald = True
48+ # target = objective.structure[objective.target_idx]
49+ #
50+ # target_vals = target.evaluate(False)
51+ # features_vals = []
52+ # nonzero_features_indexes = []
53+ # for i in range(len(objective.structure)):
54+ # if i == objective.target_idx:
55+ # continue
56+ # idx = i if i < objective.target_idx else i-1
57+ # if objective.weights_internal[idx] != 0:
58+ # features_vals.append(objective.structure[i].evaluate(False))
59+ # nonzero_features_indexes.append(idx)
60+ #
61+ # if len(features_vals) == 0:
62+ # objective.weights_final = np.zeros(len(objective.structure))
63+ # else:
64+ # features = features_vals[0]
65+ # if len(features_vals) > 1:
66+ # for i in range(1, len(features_vals)):
67+ # features = np.vstack([features, features_vals[i]])
68+ # features = np.vstack([features, np.ones(features_vals[0].shape)]) # Добавляем константную фичу
69+ # features = np.transpose(features)
70+ # estimator = LinearRegression(copy_X=True, fit_intercept=False, n_jobs=-1,
71+ # positive=False, tol=0.0001)
72+ # # estimator = LinearRegression(fit_intercept=False)
73+ # if features.ndim == 1:
74+ # features = features.reshape(-1, 1)
75+ # try:
76+ # self.g_fun_vals = global_var.grid_cache.g_func[global_var.grid_cache.g_func != 0]
77+ # except AttributeError:
78+ # self.g_fun_vals = None
79+ # estimator.fit(features, target_vals, sample_weight = self.g_fun_vals)
80+ #
81+ # valuable_weights = estimator.coef_
82+ # weights = np.zeros(len(objective.structure))
83+ # for weight_idx in range(len(weights)-1):
84+ # if weight_idx in nonzero_features_indexes:
85+ # weights[weight_idx] = valuable_weights[nonzero_features_indexes.index(weight_idx)]
86+ # weights[-1] = valuable_weights[-1]
87+ # objective.weights_final = weights
88+ # _, target, features = objective.evaluate(normalize=False, return_val=False)
89+ # self.g_fun_vals = global_var.grid_cache.g_func[global_var.grid_cache.g_func != 0]
90+ # estimator = LinearRegression(copy_X=True, fit_intercept=True, n_jobs=-1, positive=False, tol=0.0001)
91+ # estimator.fit(features, target, sample_weight=self.g_fun_vals)
92+ # valuable_weights = estimator.coef_
93+ # objective.weights_final = np.append(valuable_weights, estimator.intercept_)
94+ # objective.weights_final_evald = True
8995
9096 def use_default_tags (self ):
9197 self ._tags = {'coefficient calculation' , 'gene level' , 'no suboperators' , 'inplace' }
0 commit comments