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

Add functionality to HMM package to load and save HMMs from pickle files #36

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ncguilbeault
Copy link
Collaborator

@ncguilbeault ncguilbeault commented Nov 19, 2024

Summary

This PR adds functionality to the Bonsai.ML.HiddenMarkovModels package to enable HMMs to be saved to and loaded from pickle files on disk.

Changes

  • Fixed issue with loading and saving pickle object
  • Added include workflow for loading from pkl
  • Update package version to preview
  • Update workflow to include quotes around string path
  • Add custom unpickler to fix issue with missing module

<VersionPrefix>0.3.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionPrefix>0.3.2</VersionPrefix>
<VersionSuffix>preview-241031</VersionSuffix>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<VersionSuffix>preview-241031</VersionSuffix>
<VersionSuffix></VersionSuffix>

I would maybe keep these preview strings internal unless we publish them on nuget? There are other ways to generate prerelease strings automatically which we have developed for the main bonsai repo which we can discuss incorporating here if necessary.

</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:Exec">
<py:Script>hmm=HiddenMarkovModel(num_states=14, dimensions=2, observation_type="gaussian", init_state_distribution=[-18.4206626312063, -18.4206809139513, -1.60158960596107E-07, -18.4206809139513, -18.4206809139513, -18.4206809077833, -18.4206809139513, -18.4206809139513, -18.4206809139513, -18.4206809139512, -18.4206809139513, -18.4206809139513, -18.4206809139513, -18.4206809139513, -18.4206809139513, -18.4206809139513, -18.4049264491465], transition_matrix=[[-0.0917453060101488, -81.2027391869505, -81.2024595933819, -81.1937739522692, -81.2027400688462, -2.87807199972272, -81.2024665218064, -81.2027400688462, -81.2027400688462, -69.7226036942302, -81.0262420410483, -81.2027400688462, -81.2027400688462, -81.2027400688462, -72.3853538894001, -81.2027400686459, -3.46032916644607], [-79.3509060625393, -0.238318392160603, -79.3509060627742, -3.59028488542753, -79.3406966323115, -79.3509060343066, -2.07482406652899, -79.3509049453246, -71.8712269840478, -79.1042606674896, -64.7841761999145, -79.3509060627742, -79.3509060627736, -4.91052913823847, -79.3501000762402, -2.96596669611815, -79.3509060627742], [-6.56494712317959, -80.2574114399651, -0.026045953329265, -80.257411439958, -80.2574114399651, -80.2530342501165, -80.2574114399645, -80.2574114399651, -80.2574114399651, -80.2574114383822, -80.257411439963, -80.2574114399651, -80.2574114399651, -80.2574114399651, -80.2574111255061, -80.2574114399651, -3.71724663052794], [-79.7429093428404, -2.53565795122399, -79.7429229020156, -0.224476567256381, -79.5630094990036, -79.7427375380492, -19.7913509211774, -79.7429070271501, -79.7429229020155, -2.4282565377201, -21.6260812291176, -79.7429229020156, -79.7429229020155, -79.7429186717266, -79.5090809839381, -3.39127701396958, -79.7429229020155], [-78.8818948027961, -78.7832645463526, -78.8818948027961, -78.8499675310739, -0.121636510293837, -78.8818948027961, -78.8818779633122, -3.58627108739195, -78.4075671859456, -42.3643447224343, -78.8818948020075, -4.51454403425192, -78.7231231874378, -78.87538610611, -78.8818948027961, -2.57860476672775, -78.8818948027961], [-2.7555263648427, -81.0801260570515, -81.0801929012697, -80.8956240194587, -81.0801928008559, -0.138839571009248, -81.0735688412014, -81.0801929022382, -81.0801929022382, -7.82562008352599, -8.61673274109047, -81.0801929022382, -81.0801929022382, -81.0801929022365, -2.72606578281343, -81.0801915285753, -81.0781516310129], [-79.5041067991954, -4.1599732418435, -79.5041087741123, -2.68539625218839, -79.5041061909036, -79.5040779393979, -0.134619177577566, -79.5041087741123, -79.5041087741123, -73.6956564343321, -3.22954046210177, -79.5041087741123, -79.5041087741123, -79.4233470364088, -5.96249967131849, -79.4986866951327, -79.5041087741123], [-77.6194474368312, -77.6193823080006, -77.6194474368312, -77.619444418796, -77.6081779744754, -77.6194474368312, -77.6194468907703, -0.103028273335152, -77.6190640785059, -77.6194036382625, -77.6194474368306, -77.5387276499137, -2.3238237214254, -77.6193398550474, -77.6194474368312, -77.6189244782998, -77.6194474368312], [-79.1272032685144, -79.1271836355738, -79.1272032685144, -79.1272032685144, -4.66185628154607, -79.1272032685144, -79.1272032685137, -79.1271923677142, -0.0773138048193137, -79.1272032685144, -79.1272032685144, -4.01038951846901, -79.1225247474742, -4.13699455343842, -79.1272032685144, -3.47846842197873, -79.1272032685144], [-79.7969561517743, -79.765068795109, -79.7990815280627, -4.09625383296592, -75.3723004292721, -79.7911688467326, -79.720196927761, -79.7990800333231, -79.7990815280627, -0.133182168954187, -2.25632214661011, -79.7990815280627, -79.7990815280627, -79.7990814068833, -79.561391245246, -5.70642909748951, -79.799081522695], [-80.4624207711008, -80.4542080911501, -80.4674009479227, -2.94217521646244, -80.4642331700328, -80.4245500525541, -4.96905052833919, -80.4674009479227, -80.4674009479227, -4.80319039045672, -0.17771751882944, -80.4674009479227, -80.4674009479227, -80.4674008912272, -2.35475258982744, -80.3817582244586, -80.4674009478945], [-78.6981767986761, -78.6981767986758, -78.6981767986761, -78.6981767986761, -7.12957810042029, -78.6981767986761, -78.6981767986761, -78.6963612933677, -2.80129905358812, -78.6981767986761, -78.6981767986761, -0.0852294830554562, -3.90374244629814, -78.6981474734794, -78.6981767986761, -78.6869101761337, -78.6981767986761], [-78.3498622799896, -78.3498622799895, -78.3498622799896, -78.3498622799896, -4.01387798881909, -78.3498622799896, -78.3498622799895, -78.3452810994854, -78.2643761749177, -78.3498622799896, -78.3498622799896, -2.85311264769245, -0.0787486209906157, -78.3498612775223, -78.3498622799896, -78.3492719452334, -78.3498622799896], [-79.3538024195476, -3.13614011174884, -79.3538024195476, -79.3530894101277, -79.35193649913, -79.3538024195476, -79.33901250438, -79.3538024052913, -4.27770214689655, -79.3537999739468, -79.3538024152413, -79.3537476832867, -79.3538001630013, -0.0590336585215668, -79.3538024194494, -15.1403292390908, -79.3538024195476], [-80.8141761499455, -80.8299171351327, -80.8321243984454, -79.1140751828713, -80.7513948366163, -2.46917174255065, -59.1530651603166, -80.8321243984454, -80.8321243984454, -45.6935849036213, -2.7323847350908, -80.8321243984454, -80.8321243984454, -80.832124389641, -0.16311012032014, -7.15177346756846, -80.8321242340716], [-79.4246034910015, -3.48334852232484, -79.4246034910015, -5.7737892503062, -2.93766284446338, -79.4246034909991, -79.336913429818, -79.4164695681632, -4.34565213609343, -3.36034672586263, -79.4246014668271, -79.4244070303921, -79.4246022597813, -3.36103501832537, -79.4246034902494, -0.18535102870502, -79.4246034910015], [-3.13408601573862, -80.8656106188802, -4.3248839327091, -80.8654855265545, -80.8656106208069, -80.1649555362992, -80.8655973607584, -80.8656106208069, -80.8656106208069, -80.8382022891591, -80.8655171006304, -80.8656106208069, -80.8656106208069, -80.8656106208069, -80.8555535140235, -80.8656106208068, -0.0584500177614161]], observation_means=[[2.05933262307724, 10.8204332645415], [68.7980115395418, 149.313879689245], [0.0113367588749664, 0.0808845676209286], [36.8854430152106, 135.261998572096], [97.9835708320062, 475.786905396804], [4.85126962230773, 23.6361472322517], [44.6355192653933, 49.5566309333179], [266.329727183569, 710.965268736304], [173.521982388192, 173.718928476886], [17.616028067975, 196.233369659563], [17.0875828299435, 70.9425248823598], [204.737788814457, 189.798442944057], [260.143513242843, 262.732194667054], [122.001566709437, 101.435491122701], [9.67037560981843, 42.5625437060252], [96.2721341933364, 273.356625327438], [0.605044362615348, 3.14081365313523]], observation_covs=[[[0.905758344483852, 0], [1.2373681195321, 4.4831763035586]], [[14.3996184698293, 0], [10.9077146872554, 38.9063669683094]], [[0.015436036882364, 0], [0.109020732271086, 0.0444526519767825]], [[8.62408922415511, 0], [23.396230710446, 33.1375162351934]], [[65.0846425847929, 0], [-28.8024157037375, 67.0423181141901]], [[1.82643624659801, 0], [-1.17971110603607, 9.14393736242647]], [[10.9198108801625, 0], [3.33008442316356, 22.7612245320485]], [[51.3305896755247, 0], [13.743041597268, 189.84256808673]], [[12.5414378446675, 0], [-15.4565754923402, 78.6949525926226]], [[8.58696987374004, 0], [9.38430390783284, 66.0305935687787]], [[6.0341314486845, 0], [-9.64384045715633, 21.4295441508927]], [[9.1823933029414, 0], [13.3851117087156, 57.213049685513]], [[28.9288965124962, 0], [31.0513047915833, 60.3716689888219]], [[18.062239316743, 0], [11.8053467734538, 44.8280733649598]], [[3.79541470022462, 0], [-7.87657635998183, 13.537109427599]], [[28.3235630671307, 0], [-20.844035765898, 49.090267281817]], [[0.435879792544103, 0], [1.50536883080018, 1.53287076550159]]])</py:Script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these numbers specific fixed initialization parameters, or the result of previews runs which were saved here?

@glopesdev glopesdev added the feature New planned feature label Jan 10, 2025
@ncguilbeault ncguilbeault force-pushed the dev/hmm-load-save-from-pkl branch from 429b589 to 6ce9de0 Compare January 10, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New planned feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants