Fluent NHibernate:马尔可夫链模型
我想使用 Fluent NHibernate 来建模 马尔可夫链。它基本上是一组不同的状态,并且状态之间具有转换概率。
我想将转移概率作为字典映射到 MarkovState.TransitionProbabilities 中。我想使用 NEXT 状态作为键(使用 MarkovState 或 int 作为键),以便我可以进行如下查找:
float probability = currentState.TransitionProbabilities[nextState.Id].Probability;
我的数据库模型:
CREATE TABLE MarkovState
(
Id int IDENTITY(1,1) NOT NULL,
StateContent varchar(10) NOT NULL
);
CREATE TABLE TransitionProbability
(
Id int IDENTITY(1,1) NOT NULL,
CurrentState_Id int NOT NULL,
NextState_Id int NOT NULL,
Probability float NOT NULL
);
我的课程:
public class MarkovState
{
public virtual int Id { get; private set; }
public virtual string StateContent { get; set; }
public virtual IDictionary<int, TransitionProbability> TransitionProbabilities { get; set; }
}
public class TransitionProbability
{
public virtual int Id { get; private set; }
public virtual MarkovState CurrentState { get; set; }
public virtual MarkovState NextState { get; set; }
public virtual float Probability { get; set; }
}
和我的地图:
class MarkovStateMap : ClassMap<MarkovState>
{
public MarkovStateMap()
{
Id(x => x.Id);
Map(x => x.StateContent);
HasMany<TransitionProbability>(x => x.TransitionProbabilities)
.AsMap(x => x.NextState.Id)
.KeyColumn("CurrentState_Id")
.Not.LazyLoad()
.Inverse();
}
}
class TransitionProbabilityMap : ClassMap<TransitionProbability>
{
public TransitionProbabilityMap()
{
Id(x => x.Id);
Map(x => x.Probability);
References(x => x.CurrentState);
References(x => x.NextState);
}
}
但是,此映射似乎使用 CurrentState
作为键,而不是 NextState
。我什至不知道这个模型是否可行。如果您认为此模型无效,请提出替代方案。
I want to use Fluent NHibernate to model a Markov chain. It's basically a set of different states with transition probabilities between the states.
I want to map the transition probabilities into MarkovState.TransitionProbabilities as a Dictionary. I want to use the NEXT state as key (using either MarkovState or int as key), so that I can do lookups like:
float probability = currentState.TransitionProbabilities[nextState.Id].Probability;
My database model:
CREATE TABLE MarkovState
(
Id int IDENTITY(1,1) NOT NULL,
StateContent varchar(10) NOT NULL
);
CREATE TABLE TransitionProbability
(
Id int IDENTITY(1,1) NOT NULL,
CurrentState_Id int NOT NULL,
NextState_Id int NOT NULL,
Probability float NOT NULL
);
My classes:
public class MarkovState
{
public virtual int Id { get; private set; }
public virtual string StateContent { get; set; }
public virtual IDictionary<int, TransitionProbability> TransitionProbabilities { get; set; }
}
public class TransitionProbability
{
public virtual int Id { get; private set; }
public virtual MarkovState CurrentState { get; set; }
public virtual MarkovState NextState { get; set; }
public virtual float Probability { get; set; }
}
And my maps:
class MarkovStateMap : ClassMap<MarkovState>
{
public MarkovStateMap()
{
Id(x => x.Id);
Map(x => x.StateContent);
HasMany<TransitionProbability>(x => x.TransitionProbabilities)
.AsMap(x => x.NextState.Id)
.KeyColumn("CurrentState_Id")
.Not.LazyLoad()
.Inverse();
}
}
class TransitionProbabilityMap : ClassMap<TransitionProbability>
{
public TransitionProbabilityMap()
{
Id(x => x.Id);
Map(x => x.Probability);
References(x => x.CurrentState);
References(x => x.NextState);
}
}
However, this mapping seems to use CurrentState
as the key, and not the NextState
. I don't even know if this model is possible. Please suggest alternatives if you think this model isn't valid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许我误解了这个问题,但您的 HasMany 映射指向 CurrentState_Id。我认为你的映射应该是这样的:
Maybe I'm misunderstanding the question, but your HasMany mapping points to CurrentState_Id. I think you're mappings should look like: