Te sugerimos que revises esta respuesta en un ambiente controlado antes de enviarlo a producción, un saludo.
Ejemplo: código python de la cadena markov
import numpy as np classMarkovChain(object):def__init__(self, transition_prob):""" Initialize the MarkovChain instance. Parameters ---------- transition_prob: dict A dict object representing the transition probabilities in Markov Chain. Should be of the form: 'state1': 'state1': 0.1, 'state2': 0.4, 'state2': ... """ self.transition_prob = transition_prob self.states =list(transition_prob.keys())defnext_state(self, current_state):""" Returns the state of the random variable at the next time instance. Parameters ---------- current_state: str The current state of the system. """return np.random.choice( self.states, p=[self.transition_prob[current_state][next_state]for next_state in self.states])defgenerate_states(self, current_state, no=10):""" Generates the next states of the system. Parameters ---------- current_state: str The state of the current random variable. no: int The number of future states to generate. """ future_states =[]for i inrange(no): next_state = self.next_state(current_state) future_states.append(next_state) current_state = next_state return future_states
Te mostramos comentarios y calificaciones
Recuerda algo, que tienes la capacidad de esclarecer si topaste tu impedimento .
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)