如何在Prolog中编码因果关系(作为线性函数) [英] How to encode causal relations in Prolog (as a linear function)
问题描述
假设两个变量X和Y因果相关且线性相关,因此X的增加会导致Y的增加(例如汽车的行驶距离及其油耗). X和Y都是N个观测值的向量(在示例中为N辆单独的汽车).
Suppose that two variables X and Y are causally and linearly related, so that an increase in X produces an increase in Y (e.g. travel distance for cars and their fuel consumption). Both X and Y are vectors of N observations (N individual cars in the example).
表示这种关系的一种方法是一个简单的线性方程Yi = a + bXi,它将描述N个案例的样本中的关系,其中i = 1、2,...,N.这里a和b是常量,而Y和X是变量.
A way to represent such a relation is a simple linear equation Yi = a + bXi, which would describe the relation in the sample of N cases, where i = 1, 2, ..., N. Here a and b are constants, while Y and X are variables.
您对如何在Prolog中表示有任何建议吗?我的预感是
causes(cause(travelDistance), effect(fuelConsumption), a(0.5), b(1.23)).
.但是,这里似乎缺少的是代码,该代码指出关联具体是在X的第i个值和Y的第i个值(汽车的行驶距离和汽车的油耗)之间.
Do you have any suggestions how this could be represented in Prolog? My hunch is something like
causes(cause(travelDistance), effect(fuelConsumption), a(0.5), b(1.23)).
. What seems missing here, however, is code which states that the association specifically is between the ith value of X and the ith value of Y (a car's travel distance and that car's fuel consumption).
有什么想法吗?预先感谢!
Any ideas? Thanks in advance!
/JC
推荐答案
根据您的建议,我认为这段代码可以回答我的原始问题.谢谢!
Based on your suggestions I think this code answers my original question. Thanks!
:-use_module(library(clpfd)).
causes(
var(
name(distance),
value(Distance)
),
var(
name(fuelConsumption),
value(FuelConsumption)
)
)
:-
FuelConsumption #= 5 + 2 * Distance.
和示例查询:
?-causes(var(name(N), value(V)), var(name(fuelConsumption), value(3))).
哪个产生N = distance,V = -1
这篇关于如何在Prolog中编码因果关系(作为线性函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!