时间预估2 mathematica程序

本文介绍了一种基于历史观看数据预测连续剧集观看进度的方法。该算法通过枚举所有可能的观看速率并对其进行分类,利用每类速率的统计特征(如均值和标准差)来预测未来集数的完成时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[新的程序见:http://blog.youkuaiyun.com/barrypp/article/details/8018632]

[旧的程序见:http://blog.youkuaiyun.com/barrypp/article/details/7973575]

 

说明:对于样本数据,本程序将枚举其所有可能的速率,尝试对数据进行归类,并根据每一类的均值标准差在最新样本点上进行预测。简单来讲,基于你之前看连续剧、漫画的时间位置信息,来预测之后第几集什么时候看完。

 

时间预估2

基于对速率的统计

说明:对于样本数据,本程序将枚举其所有可能的速率,尝试对数据进行归类,并根据每一类的均值标准差在最新样本点上进行预测。


Created By Barrypp At 20120912224327
Modified By Barrypp At 20120913150856
Modified By Barrypp At 20120913172551
Modified By Barrypp At 20120913181733
TMfoF=23+25/60;LSN=26;Data={{6,2,18,0},{6,12,18,10},{7,2,18,20},{8,16,18,53},{9,15,20,11},{10,2,20,18},{11,2,20,31},{12,2,20,44},{14,2,21,23},{15,2,21,31},{16,2,21,42},{16,11,22,15},{17,2,22,18},{18,2,22,20},{19,2,22,31}};
ColorVector={Green,Blue,Cyan,Magenta,Yellow,Brown,Orange,Pink,Purple};
(*
Data的格式为,四个数字一组,示例{当前集数,已播放时间的分钟数,时间的小时数(24h),时间的分钟数};
TMfOF是Total Minutes for one File in a collection,每一集的分钟数;
LSN是Last Serial Number in a collection最后一集的集数。
*)
BeginTime=SessionTime[];

Expected[SerialNum_]:=#(SerialNum-InData[[-1,1]])+InData[[-1,2]]&/@{Mean[#]+StandardDeviation[#],Mean[#]-StandardDeviation[#]}&/@AllRateClusters
TimeMinutePart[TimeVar_]:=If[(TempX=IntegerPart[60FractionalPart[TimeVar]])>=10,TempX,StringForm["0``",TempX]]

InData={#1[[1]]+#1[[2]]/TMfoF,#1[[3]]+#1[[4]]/60}&/@Data;
WholeStandardLine[VarX_]=TMfoF VarX/60+InData[[1,2]]-TMfoF InData[[1,1]]/60;
FrontStandardLine[VarX_]=TMfoF VarX/60+InData[[-1,2]]-TMfoF InData[[-1,1]]/60;
FrontExpectedLine[VarX_]=(InData[[-1,2]]-InData[[-2,2]])/(InData[[-1,1]]-InData[[-2,1]]) (VarX-InData[[-1,1]])+InData[[-1,2]];

(*#[[2]]/#[[1]]&/@Drop[RotateLeft[InData,1]-InData,-1];*)
AllRate=Flatten[Table[#[[2]]/#[[1]],{IntegerPart[10/Min[Sqrt[#[[1]]^2+#[[2]]^2]&/@Differences[InData]]*Sqrt[#[[1]]^2+#[[2]]^2]]}]&/@Differences[InData]];

Print["请依据直方图选择适当的Man值(分类数)对数据进行分类"]
Manipulate[Histogram[(AllRateClusters= FindClusters[AllRate,Man]),100,ChartStyle->ColorVector],{{Man,Length[FindClusters[AllRate]]},1,Length[ColorVector],1}]
Dynamic[
(*TableForm[MapAt[StringForm["耗时:``ms",IntegerPart[1000*#]]&,Reverse[Timing[*)
Show[
ListPlot[InData,Mesh->Full,Joined->True,PlotStyle->Directive[Red,PointSize[Large]]],
Plot[Evaluate[Flatten[#(x-InData[[-1,1]])+InData[[-1,2]]&[AllRateClusters]]],{x,InData[[-1,1]],LSN+1},PlotStyle->Evaluate[Flatten[Table[Table[ColorVector[[i]],{Length/@AllRateClusters[[i]]}],{i,Length[AllRateClusters]}]]]],
Plot[WholeStandardLine[x],{x,InData[[1,1]],LSN+1},PlotStyle->Red],
Plot[{FrontStandardLine[x],FrontExpectedLine[x]},{x,InData[[-1,1]],LSN+1},PlotStyle->{Directive[Red,Thick],Directive[Black,Thick]}],
Plot[Evaluate[Flatten[#(x-InData[[-1,1]])+InData[[-1,2]]&[{Mean[#]+StandardDeviation[#],Mean[#]-StandardDeviation[#]}&/@AllRateClusters]]],{x,InData[[-1,1]],LSN+1},PlotStyle->None,Filling->Table[2n-1->{{2n},Directive[ColorVector[[n]],Opacity[0.25]]},{n,Length[AllRateClusters]}]]
,PlotRange->Automatic,AxesLabel->{"集数","时间"},ImageSize->Full]
(*]],2]]*)
]
Dynamic[
(*时间预计表*)
(*TableForm[MapAt[StringForm["耗时:``ms",IntegerPart[1000*#]]&,Reverse[Insert[Timing[*)
Grid[Join[{Join[{"预计开始时间","标准.全","标准.前","前端"},Table[Item[StringForm["历史速率集``",i],Background->Lighter[ColorVector[[i]]]],{i,Length[AllRateClusters]}]]},
{Join[{"数量比率"},{Null},{Null},{Null},StringForm["``%",NumberForm[#,{10,2}]]&/@N[100Length[#]/Length[AllRate]&/@AllRateClusters]]},
{Join[{"集/小时",NumberForm[N[60/TMfoF] ,{10,2}],NumberForm[N[60/TMfoF] ,{10,2}],NumberForm[N[(InData[[-1,1]]-InData[[-2,1]])/(InData[[-1,2]]-InData[[-2,2]])] ,{10,2}]},StringForm["``~``",NumberForm[N[1/#[[1]]],{10,2}],NumberForm[N[1/#[[2]]],{10,2}]]&/@(Expected[1]-Expected[0])]},Table[Join[{StringForm["第``集",n]},Item[StringForm["``:``",(TempY=IntegerPart[#]),TimeMinutePart[#]],Background->Which[TempY>=24,LightRed,TempY>=23,LightYellow,True,None]]&/@Through[{WholeStandardLine,FrontStandardLine,FrontExpectedLine}[n]],Item[StringForm["``:``~``:``",(TempY=IntegerPart[#[[2]]]),TimeMinutePart[#[[2]]],(TempZ=IntegerPart[#[[1]]]),TimeMinutePart[#[[1]]]],Background->Which[(TempY>=24)||(TempZ>=24),LightRed,(TempY>=23)||(TempZ>=23),LightYellow,True,None]]&/@Expected[n]],{n,IntegerPart[InData[[-1,1]]]+1,LSN+1}]]]
(*],{},2]],3]]*)
]

EndTime=SessionTime[];
Row[{"总体耗时(仅第一次运行):",IntegerPart[1000*(EndTime-BeginTime)],"ms"}]


 

环境是  Wolfram Research Mathematica v8.0.4.0

输出结果示例:

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值