recursion - Deedle - 具有初始值的系列上的递归映射

标签 recursion f# deedle

我正在尝试从现有的相同类型的时间序列(Series[DateTime,float])创建一个新的时间序列(Series[DateTime,float]),其中到新序列的映射是递归 - 例如:

NewSeries_T = NewSeries_T-1 + constant * OldSeries_T;

我有“NewSeries_0 = 1”,作为新系列的初始化值。

我正在尝试编写一个 Series.map 函数来完成这项工作 - 我已经得到了以下非工作代码,但我无法弄清楚递归部分:

let rec newSeries = existingSeries |> Series.map (fun k v ->     
match k.Equals(initDate) with
| true -> 1
| false -> newSeries.LastValue() + constant * v
)

所以,我认为关键是,如何允许函数访问系列中的“前一个”值以递归地构建它?

编辑 - 移至下面的答案。

最佳答案

根据 Fyodor 的推荐 - Series.scanValues 正是我所需要的:

let initalEntry = Series([initDate], [init])

let newSeries= 
    existingSeries 
    |> Series.filter (fun k v -> k.Equals(initDate) = false) 
    |> Series.scanValues (fun n x-> lambda * n + (1.0 - lambda) * x ) init

newSeries.Merge(initalEntry)

我拿走了第一个值,因为我希望它在系列开始时返回“init”值,并在最后将其合并回来。

关于recursion - Deedle - 具有初始值的系列上的递归映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548954/

相关文章:

c++ - 计算特定数字的递归函数

haskell - 将数据类型转换为映射

wpf - 使用 WPF 和 MVVM 编辑 F# 记录

f# - 元组列表上的模式匹配

f# - dotnet 互动中的 Deedle

带有时间序列的python递归矢量化

java - 递归和递归方法

f# - 在 F# 中将 native 指针与 WriteableBitmap 结合使用

f# - Deedle - readCsv 的架构格式是什么

c# - 更改 deedle 框架中的列顺序