Skip to content

Commit a97f6fd

Browse files
fixed current prototype
1 parent 653cdb9 commit a97f6fd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

batchglm/data.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,18 @@ def build_constraints(
432432
:param constraints: List of constraints as strings, e.g. "x1 + x5 = 0".
433433
:return: a model design matrix and a constraint matrix
434434
"""
435+
# TODO: automatically generate string constraints from factors
435436
di = DesignInfo(dmat.coords["design_params"])
436-
constraint_ls = []
437-
idx_constrained = []
438-
for x in constraints:
439-
constr = di.linear_constraint(x).coefs
440-
idx = np.where(constr.coefs[0] == 1)[0]
441-
constraint_ls.extend([constr])
437+
constraint_ls = [di.linear_constraint(x).coefs for x in constraints]
438+
idx_constrained = [np.where(x.coefs[0] == 1)[0] for x in constraint_ls]
439+
idx_unconstr = list(set(range(dmat.shape[1])) - set(idx_constrained))
442440

443441
dmat_var = dmat[:,idx_unconstr]
444442
constraint_mat = np.vstack(constraint_ls)[:,idx_unconstr]
445443

446444
constraints = np.vstack([
447445
np.identity(n=dmat_var.shape[1]),
448-
constraint_mat
446+
-constraint_mat
449447
])
450448
constraints_ar = xr.DataArray(
451449
dims=dims,

0 commit comments

Comments
 (0)