Skip to content

Commit

Permalink
bug fix + commit v0.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapfff committed Mar 11, 2023
1 parent 4386816 commit d888315
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# -- Project information -----------------------------------------------------

project = 'jajapy'
copyright = '2022, Raphaël Reynouard'
copyright = '2023, Raphaël Reynouard'
author = 'Raphaël Reynouard'

# The full version, including alpha/beta/rc tags
release = 'v0.10.1'
release = 'v0.10.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion jajapy/base/BW.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _preparation(self,training_set,initial_model=None, nb_states: int=None,
self._computeAlphas = self._computeAlphas_timed
self._computeBetas = self._computeBetas_timed
if type(fixed_parameters) == bool:
self.fixed_parameters = full(initial_model.matrix.shape,False)
self.fixed_parameters = full(self.h.matrix.shape,False)
else:
self.fixed_parameters = fixed_parameters

Expand Down
5 changes: 5 additions & 0 deletions jajapy/base/Base_MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def getLabel(self,state: int) -> str:
"""
self._checkStateIndex(state)
return self.labelling[state]

def b(self,state:int, label:str):
if self.getLabel(state) == label:
return 1.0
return 0.0

def getAlphabet(self) -> list:
"""
Expand Down
15 changes: 11 additions & 4 deletions jajapy/base/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ def _logLikelihood_multiproc(self, sequences: Set) -> float:
for seq,times in zip(sequences.sequences,sequences.times):
tasks.append(p.apply_async(self._computeAlphas, [seq, times,]))
temp = [res.get() for res in tasks if res.get() != False]
return sum(temp)/sum(sequences.times)
s = sum(temp)
if s == 0.0:
print('WARNING: the model is not able to generate any sequence in the set')
return 0.0
return s/sum(sequences.times)

def _computeAlphas(self,sequence: list, times: int) -> float:
"""
Expand All @@ -369,10 +373,13 @@ def _computeAlphas(self,sequence: list, times: int) -> float:
p = array([self.tau(ss,s,sequence[k]) for ss in range(self.nb_states)])
new_arr[s] = dot(prev_arr,p)
prev_arr = new_arr
if prev_arr.sum() == 0.0:
return 0.0
prev_arr *= (array([self.b(s,sequence[-1]) for s in range(self.nb_states)]))
return log(prev_arr.sum())*times
try:
res = log(prev_arr.sum())*times
except ValueError:
print("WARNING: this model is not able to generate this sequence")
res = False
return res

def _checkStateIndex(self,s:int) -> None:
if type(s) != int:
Expand Down
1 change: 1 addition & 0 deletions jajapy/ctmc/CTMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def e(self,s: int) -> float:
"""
self._checkStateIndex(s)
return sum(self.matrix[s])


def l(self, s1:int, s2:int, obs:str) -> float:
"""
Expand Down
5 changes: 0 additions & 5 deletions jajapy/mc/MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ def a(self,s1: int,s2: int) -> float:
self._checkStateIndex(s2)
return self.matrix[s1][s2]

def b(self,state:int, label:str):
if self.getLabel(state) == label:
return 1.0
return 0.0

def next(self,state: int) -> tuple:
"""
Return a state-observation pair according to the distributions described by `matrix`
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
packages=find_packages(),
install_requires=['numpy', 'scipy', 'alive-progress','sympy'],
long_description_content_type="text/markdown",
version='0.10.1',
version='0.10.2',
url="",
description='Baum-Welch for all kind of Markov model',
author='Raphaël Reynouard',
Expand Down

0 comments on commit d888315

Please sign in to comment.