Skip to content

Commit

Permalink
tried some approaches, making mu a vector not worth it, too long with…
Browse files Browse the repository at this point in the history
… the current method
  • Loading branch information
AlexYFM committed Aug 7, 2024
1 parent 1b6c4ad commit 9c0a4a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 9 additions & 0 deletions demo/dryvr_demo/thermo_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class ThermoMode(Enum):
# fig = go.Figure()
# fig = simulation_tree(traces, None, fig, 2, 1, [2, 1], "lines", "trace")

# basis = np.array([[ 0.34474,-0.00154],[-0.00012,-0.02748]])
# center = np.array([-960.47483,6.7487])
# C = np.transpose(np.array([[1, 0, -1, 0], [0, 1, 0, -1]]))
# g = np.array([3030.84222,39.5072,-2989.43095,-35.91564,])
# StarSet(center, basis, C, g).plot()
# exit()
### issue could be twofold as basestarsensor is also replace the bespoke therm sensor, which could be causing the errors
### big issue: why are timers unsynched/not a multple of the ts? e.g., seeing this average time: [82.94445 1.15482 0.1 ]?
### deepest issue though is why would post_cont_pca ever unsat for this?
basis = np.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) * np.diag([0.1, 0, 0]) # this doesn't actually make sense, but not sure how algorithm actually handles 1d polytopes
center = np.array([75.5,0,0])
C = np.transpose(np.array([[1,-1,0,0,0,0],[0,0,1,-1,0,0], [0,0,0,0,1,-1]]))
Expand Down
10 changes: 3 additions & 7 deletions verse/stars/starset.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,14 @@ def post_cont_pca(old_star: StarSet, derived_basis: np.ndarray, points: np.ndar
raise ValueError(f'Dimension of given basis does not match basis of original starset')

center, basis, C, g = old_star.center, old_star.basis, old_star.C, old_star.g

old_star.print()
print(derived_basis)
print(np.average(points, axis=0))

alpha = [RealVector(f'a_{i}', C.shape[1]) for i in range(points.shape[0])]
u = Real('u')
c = RealVector('i', old_star.dimension())
# u = RealVector('u', C.shape[0])

o = Optimize()
### add equality constraints
Expand All @@ -644,15 +643,14 @@ def post_cont_pca(old_star: StarSet, derived_basis: np.ndarray, points: np.ndar
exp = 0 # there's probably a better way to do this, but this works
for j in range(len(alpha[p])): # iterate over alphas
exp += C[i][j]*alpha[p][j]
# print(exp)
o.add(exp <= u*g[i])
# o.add(exp <= u[i]*g[i])

o.minimize(u)

model = None
new_basis = derived_basis
if o.check() == sat:

if o.check() == sat:
model = o.model()
new_basis = derived_basis * float(model[u].as_fraction())
else:
Expand All @@ -662,9 +660,7 @@ def post_cont_pca(old_star: StarSet, derived_basis: np.ndarray, points: np.ndar

# return StarSet(new_center, derived_basis, C, g * float(model[u].as_fraction()))
new_center = np.array([float(model[c[i]].as_fraction()) for i in range(len(c))])

print('---------\n---------')
StarSet(new_center, derived_basis, C, g * float(model[u].as_fraction())).print()

return StarSet(new_center, derived_basis, C, g * float(model[u].as_fraction()))
# return old_star.superposition(new_center, new_basis)
Expand Down

0 comments on commit 9c0a4a7

Please sign in to comment.