Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 0.1.2 #93

Merged
merged 74 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
0a75fe6
SeqART
NiklasMelton Aug 20, 2024
7073514
Add initial implementation of cvi Art Modules.
Aug 22, 2024
0c036d0
sequence ART
NiklasMelton Aug 25, 2024
59c0adc
implement original match reset
NiklasMelton Aug 25, 2024
a031037
add argument for modified match reset
NiklasMelton Aug 26, 2024
151204b
add argument for modified match reset
NiklasMelton Aug 26, 2024
9859568
add argument for modified match reset
NiklasMelton Aug 26, 2024
487b27d
fix fusion ART
NiklasMelton Aug 26, 2024
acdf996
fix topo art
NiklasMelton Aug 26, 2024
3458bb3
Merge pull request #71 from NiklasMelton/artmap-fixes
NiklasMelton Aug 26, 2024
2e9c926
add artmap regression
NiklasMelton Aug 26, 2024
8858765
Merge pull request #72 from NiklasMelton/regression
NiklasMelton Aug 26, 2024
47e6e52
FusionART regression
NiklasMelton Aug 26, 2024
72ea572
Merge pull request #73 from NiklasMelton/regression
NiklasMelton Aug 26, 2024
9e43468
Merge pull request #70 from DustinTanksley/develop
NiklasMelton Aug 26, 2024
59efb7a
cammel case to snake case
NiklasMelton Aug 26, 2024
d715637
clean cvi ART and add examples
NiklasMelton Aug 26, 2024
4f9e21c
Merge pull request #74 from NiklasMelton/add-cvi-examples
NiklasMelton Aug 26, 2024
d1e9134
generalize CVI ART
NiklasMelton Aug 26, 2024
8055f18
Merge pull request #75 from NiklasMelton/generalize-cvi-art
NiklasMelton Aug 26, 2024
153ae67
fix match-tracking for fusionART
NiklasMelton Aug 26, 2024
a2a0b16
fix match-tracking for fusionART
NiklasMelton Aug 26, 2024
e2fe2d6
Merge pull request #76 from NiklasMelton/fix-fusion-art
NiklasMelton Aug 26, 2024
03ef3e0
Add and test FALCON
NiklasMelton Aug 28, 2024
5cdd270
Merge pull request #77 from NiklasMelton/FALCON
NiklasMelton Aug 28, 2024
3720fd9
convex-hull-art
NiklasMelton Aug 29, 2024
37a38e7
convex-hull-art
NiklasMelton Aug 29, 2024
3a8d1ea
Merge pull request #78 from NiklasMelton/experimental-convex-hull-art
NiklasMelton Aug 29, 2024
fb29a52
update activation for points and lines
NiklasMelton Aug 29, 2024
cf026be
Merge pull request #79 from NiklasMelton/update-convex-hull-art
NiklasMelton Aug 29, 2024
53b361b
Merge branch 'develop' into seq-art
NiklasMelton Aug 29, 2024
b30fb03
move to experimental
NiklasMelton Aug 29, 2024
08e9a55
move to experimental
NiklasMelton Aug 29, 2024
be59a58
Merge pull request #69 from NiklasMelton/seq-art
NiklasMelton Aug 29, 2024
df0165c
bump version
NiklasMelton Aug 29, 2024
49b0a87
Create pypi-publish.yml
NiklasMelton Aug 29, 2024
b7c1ef9
update-readme
NiklasMelton Sep 1, 2024
b9a06e9
update-readme
NiklasMelton Sep 1, 2024
58a8a6b
Merge pull request #80 from NiklasMelton/update-readme
NiklasMelton Sep 1, 2024
1b4e5a5
bug fixes
NiklasMelton Sep 6, 2024
16d4015
Merge pull request #81 from NiklasMelton/bug-fixes
NiklasMelton Sep 6, 2024
c4dea3e
add td-falcon
NiklasMelton Sep 6, 2024
fa14978
add td-falcon
NiklasMelton Sep 6, 2024
4571773
add td-falcon
NiklasMelton Sep 6, 2024
d9b6136
Merge pull request #82 from NiklasMelton/td-falcon
NiklasMelton Sep 6, 2024
1210888
update prepare_data method
NiklasMelton Sep 6, 2024
ed2ef34
add restore data method
NiklasMelton Sep 7, 2024
7c07182
add restore data method
NiklasMelton Sep 7, 2024
a90a091
Merge pull request #83 from NiklasMelton/prepare-data-changes
NiklasMelton Sep 7, 2024
7b439b3
add VAT
NiklasMelton Sep 9, 2024
f453aa5
add VAT citation
NiklasMelton Sep 9, 2024
71acd02
Merge pull request #85 from NiklasMelton/VAT
NiklasMelton Sep 9, 2024
115fa99
add VAT citation
NiklasMelton Sep 9, 2024
282e6a7
Merge pull request #86 from NiklasMelton/VAT
NiklasMelton Sep 9, 2024
4dbb726
update VAT to be a bit faster
NiklasMelton Sep 9, 2024
44868ac
update VAT to be a bit faster
NiklasMelton Sep 9, 2024
42554e5
Merge pull request #87 from NiklasMelton/update-VAT
NiklasMelton Sep 9, 2024
9ab0f8c
column-wise normalization
NiklasMelton Sep 9, 2024
fb7a824
fix artmap bug
NiklasMelton Sep 10, 2024
27cec4e
Merge pull request #88 from NiklasMelton/artmap-bug-fix
NiklasMelton Sep 10, 2024
ef472de
match tracking versions added
NiklasMelton Sep 10, 2024
a9b6af2
match tracking versions added
NiklasMelton Sep 10, 2024
0c91e9e
match tracking versions added
NiklasMelton Sep 10, 2024
0b43c1c
match tracking versions added
NiklasMelton Sep 10, 2024
dd7392f
Merge pull request #89 from NiklasMelton/match-tracking-versions
NiklasMelton Sep 10, 2024
567cf6e
optimize MT~
NiklasMelton Sep 14, 2024
3644656
Merge branch 'develop' into column-wise-normalization
NiklasMelton Sep 16, 2024
9e800a2
Merge pull request #90 from NiklasMelton/column-wise-normalization
NiklasMelton Sep 16, 2024
86d0264
Merge branch 'develop' into artmap-reset-update
NiklasMelton Sep 16, 2024
69a2f54
Merge pull request #91 from NiklasMelton/artmap-reset-update
NiklasMelton Sep 16, 2024
c88bd92
improve match-tracking
NiklasMelton Sep 18, 2024
97a5121
improve gaussian art
NiklasMelton Sep 26, 2024
59d674f
Merge pull request #92 from NiklasMelton/match-tracking-update
NiklasMelton Sep 26, 2024
4c69a9e
Merge branch 'main' into develop
NiklasMelton Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add and test FALCON
  • Loading branch information
NiklasMelton committed Aug 28, 2024
commit 03ef3e0d40b7f508f5f1027cf005b57bf309f234
2 changes: 2 additions & 0 deletions artlib/__init__.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@

from artlib.fusion.FusionART import FusionART

from artlib.reinforcement.FALCON import FALCON

from artlib.biclustering.BARTMAP import BARTMAP

from artlib.topological.TopoART import TopoART
3 changes: 3 additions & 0 deletions artlib/common/BaseART.py
Original file line number Diff line number Diff line change
@@ -490,6 +490,9 @@ def predict(self, X: np.ndarray) -> np.ndarray:
y[i] = c
return y

def shrink_clusters(self, shrink_ratio: float = 0.1):
return self

def plot_cluster_bounds(self, ax: Axes, colors: Iterable, linewidth: int = 1):
"""
undefined function for visualizing the bounds of each cluster
13 changes: 13 additions & 0 deletions artlib/elementary/FuzzyART.py
Original file line number Diff line number Diff line change
@@ -199,6 +199,19 @@ def get_cluster_centers(self) -> List[np.ndarray]:
centers.append(np.array(ref_points)+0.5*np.array(widths))
return centers

def shrink_clusters(self, shrink_ratio: float = 0.1):
new_W = []
dim = len(self.W[0])//2
for w in self.W:
new_w = np.copy(w)
widths = (1-w[dim:]) - w[:dim]
new_w[:dim] += widths*shrink_ratio
new_w[dim:] += widths*shrink_ratio
new_W.append(new_w)
self.W = new_W
return self


def plot_cluster_bounds(self, ax: Axes, colors: Iterable, linewidth: int = 1):
"""
undefined function for visualizing the bounds of each cluster
31 changes: 30 additions & 1 deletion artlib/fusion/FusionART.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
doi:10.1007/ 978-3-540-72383-7_128.
"""
import numpy as np
from typing import Optional, Union, Callable, List
from typing import Optional, Union, Callable, List, Literal
from copy import deepcopy
from artlib.common.BaseART import BaseART
from sklearn.utils.validation import check_is_fitted
@@ -256,6 +256,35 @@ def _step_fit_original(self, x: np.ndarray, match_reset_func: Optional[Callable]
self.modules[i].params = base_params[i]
return c_new

def partial_fit(self, X: np.ndarray, match_reset_func: Optional[Callable] = None, match_reset_method: Literal["original", "modified"] = "original"):
"""
iteratively fit the model to the data

Parameters:
- X: data set
- match_reset_func: a callable accepting the data sample, a cluster weight, the params dict, and the cache dict
Permits external factors to influence cluster creation.
Returns True if the cluster is valid for the sample, False otherwise
- match_reset_method: either "original" or "modified"

"""

self.validate_data(X)
self.check_dimensions(X)
self.is_fitted_ = True

if not hasattr(self.modules[0], 'W'):
self.W: list[np.ndarray] = []
self.labels_ = np.zeros((X.shape[0], ), dtype=int)
j = 0
else:
j = len(self.labels_)
self.labels_ = np.pad(self.labels_, [(0, X.shape[0])], mode='constant')
for i, x in enumerate(X):
c = self.step_fit(x, match_reset_func=match_reset_func, match_reset_method=match_reset_method)
self.labels_[i+j] = c
return self

def step_pred(self, x, skip_channels: List[int] = []) -> int:
"""
predict the label for a single sample
84 changes: 84 additions & 0 deletions artlib/reinforcement/FALCON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np
from typing import Optional, Literal
from artlib import FusionART, BaseART


class FALCON:
def __init__(
self,
state_art: BaseART,
action_art: BaseART,
reward_art: BaseART,
gamma_values: list[float] = np.array([0.33, 0.33, 0.34]),
channel_dims = list[int]
):
self.fusion_art = FusionART(
modules=[state_art, action_art, reward_art],
gamma_values=gamma_values,
channel_dims=channel_dims
)

def fit(self, states: np.ndarray, actions: np.ndarray, rewards: np.ndarray):
data = self.fusion_art.join_channel_data([states, actions, rewards])
self.fusion_art = self.fusion_art.fit(data)
return self

def partial_fit(self, states: np.ndarray, actions: np.ndarray, rewards: np.ndarray):
data = self.fusion_art.join_channel_data([states, actions, rewards])
self.fusion_art = self.fusion_art.partial_fit(data)
return self

def get_actions_and_rewards(self, state: np.ndarray, action_space: Optional[np.ndarray] = None) -> np.ndarray:
reward_centers = self.fusion_art.get_channel_centers(2)
if action_space is None:
action_space = self.fusion_art.get_channel_centers(1)
action_space = np.array(action_space)
action_space_prepared = self.fusion_art.modules[0].prepare_data(action_space)
viable_clusters = []
for action in action_space_prepared:
data = self.fusion_art.join_channel_data([state.reshape(1, -1), action.reshape(1, -1)], skip_channels=[2])
c = self.fusion_art.predict(data, skip_channels=[2])
viable_clusters.append(c[0])

rewards = [reward_centers[c] for c in viable_clusters]

return action_space, np.array(rewards)
def get_action(self, state: np.ndarray, action_space: Optional[np.ndarray] = None, optimality: Literal["min", "max"] = "max") -> np.ndarray:
action_space, rewards = self.get_actions_and_rewards(state, action_space)
if optimality == "max":
c_winner = np.argmax(rewards)
else:
c_winner = np.argmin(rewards)
return action_space[c_winner]

def get_probabilistic_action(self, state: np.ndarray, action_space: Optional[np.ndarray] = None, offset: float = 0.1, optimality: Literal["min", "max"] = "max") -> np.ndarray:
action_space, rewards = self.get_actions_and_rewards(state, action_space)
action_indices = np.array(range(len(action_space)))


reward_dist = rewards
reward_dist /= np.sum(reward_dist)
reward_dist = reward_dist.reshape((-1,))

if optimality == "min":
reward_dist = 1.-reward_dist

reward_dist = np.maximum(np.minimum(reward_dist, offset), 0.0001)
reward_dist /= np.sum(reward_dist)

a_i = np.random.choice(action_indices, size=1, p=reward_dist)
return action_space[a_i[0]][0]

def get_rewards(self, states: np.ndarray, actions: np.ndarray) -> np.ndarray:
reward_centers = self.fusion_art.get_channel_centers(2)
data = self.fusion_art.join_channel_data([states, actions], skip_channels=[2])
C = self.fusion_art.predict(data, skip_channels=[2])
return np.array([reward_centers[c] for c in C])








Loading