Giter Club home page Giter Club logo

diglm's People

Contributors

antuvenciu avatar marcoriggirello avatar

Stargazers

 avatar

Watchers

 avatar

diglm's Issues

Docstring di NeuralSplineFlow migliorabile

La documentazione di NeuralSplineFlow, in particolare la spiegazione dei due argomenti mutuamente esclusivi, masks e splits, parmi vaporosa e poco esplicativa. Certamente si possono trovare maniere più efficaci di scrivere, sarò lieto di ascoltare i tuoi preziosi suggerimenti.

failing to import from diglm

Sto avendo il seguente problema a importare la classe DIGLM dal modulo diglm.py:

from diglm import DIGLM

ImportError: cannot import name 'DIGLM' from 'diglm' (/content/diglm/diglm/__init__.py)

Gli altri import funzionano. Forse c'è bisogno di qualche nome speciale per chiamare moduli in pacchetti con lo stesso nome? Forse non si fa? In rete ho trovato un riferimento proprio a questo.

Look here.

Propongo di dare al pacchetto il nome DIGLM, al modulo il nome diglm, alla classe il nome Diglm

Bug (?) in diglm.weighted_log_prob

Questa è la funzione di training sulla quale sto eseguendo il loop:

@tf.function
def train_step(optimizer, target_sample):
with tf.GradientTape() as tape:
loss = -tf.reduce_mean(diglm.weighted_log_prob(target_sample))
variables = tape.watched_variables()
gradients = tape.gradient(loss, variables)
optimizer.apply_gradients(zip(gradients, variables))
return loss

E sto chiamando così la funzione nel loop:
`LR = 1e-3
NUM_EPOCHS = 100

learning_rate = tf.Variable(LR, trainable=False)
optimizer = tf.keras.optimizers.Adam(learning_rate)

loss = 0

for epoch in range(NUM_EPOCHS):
if epoch % 10 == 9:
print(f"Epoch n. {epoch+1}. Loss={loss}.")
for i in range(int(DATASET_SIZE/BATCH_SIZE)):
batch_label = y_data.sample(BATCH_SIZE, random_state=42)
batch_feature = data_train.sample(BATCH_SIZE, random_state=42)
loss = train_step(optimizer, tf.tuple(batch_label, batch_feature))`

Trovo il seguente errore:

`AttributeError Traceback (most recent call last)

in ()
13 batch_label = y_data.sample(BATCH_SIZE, random_state=42)
14 batch_feature = data_train.sample(BATCH_SIZE, random_state=42)
---> 15 loss = train_step(optimizer, tf.tuple(batch_label, batch_feature))

1 frames

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise

AttributeError: in user code:

File "<ipython-input-45-8c287debb608>", line 4, in train_step  *
    loss = -tf.reduce_mean(diglm.weighted_log_prob(target_sample))
File "/content/SpQR-Flow/SpQR-Flow/diglm.py", line 68, in weighted_log_prob  *
    lpp = self.log_prob_parts(value)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 579, in log_prob_parts  **
    self._map_measure_over_dists('log_prob', value),
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 750, in _map_measure_over_dists
    lambda dist, value, **_: ValueWithTrace(value=value,  # pylint: disable=g-long-lambda
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 834, in _call_execute_model
    flat_value = None if value is None else self._model_flatten(value)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/distributions/joint_distribution_named.py", line 342, in _model_flatten
    return tuple(getattr(xs, n) for n in self._dist_fn_name)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/distributions/joint_distribution_named.py", line 342, in <genexpr>
    return tuple(getattr(xs, n) for n in self._dist_fn_name)

AttributeError: 'Tensor' object has no attribute 'features'`

che secondo me dipende dal fatto che il seguente codice:

def weighted_log_prob(self, value, scaling_const=.1): lpp = self.log_prob_parts(value) return lpp["labels"] + scaling_const * lpp["features"]

invoca lpp come se fosse un dizionario, ma non è vero:
dalla documentazione su tesnorflow_probability.distributions.JointDistributionNamedAutoBached il return value è:
"a tuple of Tensors representing the log_prob for each distribution_fn evaluated at each corresponding value."

data sampling

Riporto il seguente errore nel tentativo di creare un sample dalle distribuzioni trasformate col bijector NeuralSplineFlow:

`import tensorflow as tf
from tensorflow_probability import distributions as tfd
from tensorflow_probability import bijectors as tfb

from spqr import NeuralSplineFlow as NSF

neural_spline_flow = NSF(splits=2)

base_loc = np.zeros(22).astype(np.float32)
base_var = np.ones(22).astype(np.float32)
base_dist = tfd.MultivariateNormalDiag(loc=base_loc, scale_diag=base_var)

trans_dist = tfd.TransformedDistribution(base_dist,
bijector=neural_spline_flow)

trans_dist.sample(1)
TypeError Traceback (most recent call last)
in
----> trans_dist.sample(1)

~/.local/lib/python3.10/site-packages/tensorflow_probability/python/distributions/distribution.py in sample(self, sample_shape, seed, name, **kwargs)
1232 """
1233 with self._name_and_control_scope(name):
-> 1234 return self._call_sample_n(sample_shape, seed, **kwargs)
1235
1236 def _call_sample_and_log_prob(self, sample_shape, seed, **kwargs):

~/.local/lib/python3.10/site-packages/tensorflow_probability/python/distributions/transformed_distribution.py in _call_sample_n(self, sample_shape, seed, **kwargs)
330 # work, it is imperative that this is the last modification to the
331 # returned result.
--> 332 return self.bijector.forward(x, **bijector_kwargs)
333
334 def _sample_and_log_prob(self, sample_shape, seed, **kwargs):
.
.
.
.
.
.

TypeError: 'NoneType' object is not callable
Spero che col poco codice che ho messo l'errore sia riproducibile. Il metodosample` esiste, ma pare che non sia invocabile dal nostro oggetto (?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.