likelihood 1.2.15__py3-none-any.whl → 1.2.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,12 +6,11 @@ import numpy as np
6
6
  import pandas as pd
7
7
  import tensorflow as tf
8
8
  from pandas.core.frame import DataFrame
9
- from tensorflow.keras.models import Model
10
9
 
11
10
  from likelihood.tools import OneHotEncoder
12
11
 
13
12
 
14
- class AutoClassifier(Model):
13
+ class AutoClassifier(tf.keras.Model):
15
14
  """
16
15
  An auto-classifier model that automatically determines the best classification strategy based on the input data.
17
16
 
@@ -23,6 +22,10 @@ class AutoClassifier(Model):
23
22
 
24
23
  Methods:
25
24
  __init__(self, input_shape, num_classes, units, activation): Initializes an AutoClassifier instance with the given parameters.
25
+ build(self, input_shape): Builds the model architecture based on input_shape.
26
+ call(self, x): Defines the forward pass of the model.
27
+ get_config(self): Returns the configuration of the model.
28
+ from_config(cls, config): Recreates an instance of AutoClassifier from its configuration.
26
29
  """
27
30
 
28
31
  def __init__(self, input_shape, num_classes, units, activation):
@@ -41,33 +44,59 @@ class AutoClassifier(Model):
41
44
  The type of activation function to use for the neural network layers.
42
45
  """
43
46
  super(AutoClassifier, self).__init__()
47
+ self.input_shape = input_shape
48
+ self.num_classes = num_classes
44
49
  self.units = units
45
- self.shape = input_shape
50
+ self.activation = activation
46
51
 
52
+ self.encoder = None
53
+ self.decoder = None
54
+ self.classifier = None
55
+
56
+ def build(self, input_shape):
47
57
  self.encoder = tf.keras.Sequential(
48
58
  [
49
- tf.keras.layers.Dense(units=units, activation=activation),
50
- tf.keras.layers.Dense(units=int(units / 2), activation=activation),
59
+ tf.keras.layers.Dense(units=self.units, activation=self.activation),
60
+ tf.keras.layers.Dense(units=int(self.units / 2), activation=self.activation),
51
61
  ]
52
62
  )
53
63
 
54
64
  self.decoder = tf.keras.Sequential(
55
65
  [
56
- tf.keras.layers.Dense(units=units, activation=activation),
57
- tf.keras.layers.Dense(units=input_shape, activation=activation),
66
+ tf.keras.layers.Dense(units=self.units, activation=self.activation),
67
+ tf.keras.layers.Dense(units=self.input_shape, activation=self.activation),
58
68
  ]
59
69
  )
60
70
 
61
71
  self.classifier = tf.keras.Sequential(
62
- [tf.keras.layers.Dense(num_classes, activation="softmax")]
72
+ [tf.keras.layers.Dense(self.num_classes, activation="softmax")]
63
73
  )
64
74
 
65
75
  def call(self, x):
66
76
  encoded = self.encoder(x)
67
77
  decoded = self.decoder(encoded)
68
78
  combined = tf.concat([decoded, encoded], axis=1)
69
- classifier = self.classifier(combined)
70
- return classifier
79
+ classification = self.classifier(combined)
80
+ return classification
81
+
82
+ def get_config(self):
83
+ config = {
84
+ "input_shape": self.input_shape,
85
+ "num_classes": self.num_classes,
86
+ "units": self.units,
87
+ "activation": self.activation,
88
+ }
89
+ base_config = super(AutoClassifier, self).get_config()
90
+ return dict(list(base_config.items()) + list(config.items()))
91
+
92
+ @classmethod
93
+ def from_config(cls, config):
94
+ return cls(
95
+ input_shape=config["input_shape"],
96
+ num_classes=config["num_classes"],
97
+ units=config["units"],
98
+ activation=config["activation"],
99
+ )
71
100
 
72
101
 
73
102
  def call_existing_code(
likelihood/tools/tools.py CHANGED
@@ -815,7 +815,10 @@ class DataFrameEncoder:
815
815
  self._df[i] = self._df[i].apply(
816
816
  self._code_transformation_to, dictionary_list=encode_dict
817
817
  )
818
- median_value = len(self._df[i].unique()) // 2
818
+ if len(self._df[i].unique()) > 1:
819
+ median_value = len(self._df[i].unique()) // 2
820
+ else:
821
+ median_value = 1.0
819
822
  if norm_method == "median":
820
823
  self._df[i] = self._df[i].astype("float64")
821
824
  self._df[i] = self._df[i] / median_value
@@ -842,6 +845,8 @@ class DataFrameEncoder:
842
845
  print("Configuration detected")
843
846
  if len(self.median_list) == len(self._encode_columns):
844
847
  median_mode = True
848
+ else:
849
+ median_mode = False
845
850
  for num, colname in enumerate(self._encode_columns):
846
851
  if self._df[colname].dtype == "object":
847
852
  encode_dict = self.encoding_list[num]
@@ -859,6 +864,8 @@ class DataFrameEncoder:
859
864
  df_decoded = self._df.copy()
860
865
  if len(self.median_list) == len(self._encode_columns):
861
866
  median_mode = True
867
+ else:
868
+ median_mode = False
862
869
  try:
863
870
  number_of_columns = len(self.decoding_list[j])
864
871
  for i in self._encode_columns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: likelihood
3
- Version: 1.2.15
3
+ Version: 1.2.16
4
4
  Summary: A package that performs the maximum likelihood algorithm.
5
5
  Home-page: https://github.com/jzsmoreno/likelihood/
6
6
  Author: J. A. Moreno-Guerra
@@ -7,12 +7,12 @@ likelihood/models/regression.py,sha256=9cakyGlJCEO6WfpoKLh3GxdXQeQp7cUvJIkQ5odT0
7
7
  likelihood/models/simulation.py,sha256=KYdVjt2PaLo04g8kBsRGQJ5AKMBaQVUH3orZE_TXTy8,2960
8
8
  likelihood/models/utils.py,sha256=VtEj07lV-GRoWraQgpfjU0jTt1Ntf9MXgYwe6XYQh20,1552
9
9
  likelihood/models/deep/__init__.py,sha256=-KIPippVaMqgG8mEgYjNxYQdqOUcFhUuKhbVe8TTCfo,28
10
- likelihood/models/deep/autoencoders.py,sha256=12kPN0UlXyDcqZuysf9KwALsH-Oi1HqPDVR1a8EJsLA,7710
10
+ likelihood/models/deep/autoencoders.py,sha256=wgra29Wjyh4KOMdOVEhWLtfqTFvjKeOVf1GthomB7PE,8857
11
11
  likelihood/tools/__init__.py,sha256=MCjsCWfBNKE2uMN0VizDN1uFzZ_md0X2WZeBdWhrCR8,50
12
12
  likelihood/tools/numeric_tools.py,sha256=EQD959b56aovi4PI_og0BITgyUONgDUU9LG9YqNgX70,7554
13
- likelihood/tools/tools.py,sha256=zfrGKgRjz9G_hmJkpf8VYuJ6PsfwWvWTxqao_b2vydw,41412
14
- likelihood-1.2.15.dist-info/LICENSE,sha256=XWHWt9egYEUHGPTnlcZfJKLPmysacOwdiLj_-J7Z9ew,1066
15
- likelihood-1.2.15.dist-info/METADATA,sha256=Z-iU581E4E9kSuwr3coAkS_T6Z9N5cr_CMzr_us2dds,2463
16
- likelihood-1.2.15.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
17
- likelihood-1.2.15.dist-info/top_level.txt,sha256=KDiBLr870YTxqLFqObTOSrTK10uw8dFsITSNLlte3PA,11
18
- likelihood-1.2.15.dist-info/RECORD,,
13
+ likelihood/tools/tools.py,sha256=B1_xRZeO2fUSCVUvdkhlB6zO9dGzIglSknydLv7VCEc,41627
14
+ likelihood-1.2.16.dist-info/LICENSE,sha256=XWHWt9egYEUHGPTnlcZfJKLPmysacOwdiLj_-J7Z9ew,1066
15
+ likelihood-1.2.16.dist-info/METADATA,sha256=5htpwpnzwy5Y0sU103sm_K8Yt5xhMjjmLf1a3rx_40s,2463
16
+ likelihood-1.2.16.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
17
+ likelihood-1.2.16.dist-info/top_level.txt,sha256=KDiBLr870YTxqLFqObTOSrTK10uw8dFsITSNLlte3PA,11
18
+ likelihood-1.2.16.dist-info/RECORD,,