Skip to content

Commit

Permalink
FIX: report and knowledge cache
Browse files Browse the repository at this point in the history
  • Loading branch information
maffettone committed Dec 13, 2023
1 parent 4412752 commit 15ee232
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bmm_agents/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def trigger_condition(self, uid) -> bool:
and self.exp_catalog[uid].start["XDI"]["Element"]["symbol"] == self.analyzed_element_and_edge[0]
)

def report(self, **kwargs):
arr = np.array(self.observable_cache)
self.model.fit(arr)
return dict(
cluster_centers=self.model.cluster_centers_,
cache_len=len(self.independent_cache),
latest_data=self.tell_cache[-1],
)


class ActiveKmeansAgent(PassiveKmeansAgent):
def __init__(self, *args, bounds: ArrayLike, min_step_size: float = 0.01, **kwargs):
Expand Down Expand Up @@ -102,8 +111,8 @@ def server_registrations(self) -> None:
def tell(self, x, y):
"""A tell that adds to the local discrete knowledge cache, as well as the standard caches.
Uses relative coords for x"""
self.knowledge_cache.add(make_hashable(discretize(x, self.min_step_size)))
doc = super().tell(x - self.element_origins[0, self._element_idx], y)
self.knowledge_cache.add(make_hashable(discretize(doc["independent_variable"], self.min_step_size)))
doc["absolute_position_offset"] = self.element_origins[0, self._element_idx]
return doc

Expand Down
1 change: 1 addition & 0 deletions bmm_agents/startup_scripts/mmm4_Pt_kmeans.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import tiled.client.node
from bluesky_adaptive.server import register_variable, shutdown_decorator, startup_decorator

from bmm_agents.sklearn import MultiElementActiveKmeansAgent
Expand Down

0 comments on commit 15ee232

Please sign in to comment.