时间预估2 mathematica程序 [改]

[旧的程序见:http://blog.csdn.net/barrypp/article/details/7976132]

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

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

Created By Barrypp At 20120912224327
Modified By Barrypp At 20120913150856
Modified By Barrypp At 20120913172551
Modified By Barrypp At 20120913181733
Modified By Barrypp At 20120914201238
Modified By Barrypp At 20120915012255
Modified By Barrypp At 20120915015654
Modified By Barrypp At 20120920174555
Modified By Barrypp At 20120923125103
Modified By Barrypp At 20120924184900
TMfoF=24+45/60;LSN=12;Data={{2,12,19,27},{3,3,19,42},{4,2.5,20,5},{6,0.5,20,49},{7,0,21,7},{8,0,21,21}};
ColorVector={Green,Blue,Cyan,Brown,Orange,Pink};
(*
Data的格式为,四个数字一组,示例{当前集数,已播放时间的分钟数,时间的小时数(24h),时间的分钟数};
TMfOF是Total Minutes for one File in a collection,每一集的分钟数;
LSN是Last Serial Number in a collection最后一集的集数。
*)
BeginTime=AbsoluteTime[];

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 /60*(VarX-InData[[1,1]])+InData[[1,2]];
FrontStandardLine[VarX_]=TMfoF /60*(VarX-InData[[-1,1]])+InData[[-1,2]];
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,Method->"Agglomerate"]),70,ChartStyle->ColorVector],{{Man,Length[FindClusters[AllRate,Method->"Agglomerate"]]},1,Length[ColorVector],1},TrackedSymbols:>{Man}]

Dynamic[
Expected[SerialNum_]=#(SerialNum-InData[[-1,1]])+InData[[-1,2]]&/@{Mean[#]+StandardDeviation[#],Mean[#]-StandardDeviation[#]}&/@AllRateClusters;
,TrackedSymbols:>{AllRateClusters}
]


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]]&[DeleteDuplicates/@AllRateClusters]]],{x,InData[[-1,1]],LSN+1},PlotStyle->Evaluate[Flatten[Table[Table[ColorVector[[i]],{Length/@(DeleteDuplicates/@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[Expected[x]]],{x,InData[[-1,1]],LSN+1},PlotStyle->None,Filling->Table[2n-1->{{2n},Directive[ColorVector[[n]],Opacity[0.25]]},{n,Length[AllRateClusters]}]],
Plot[{24,23},{x,InData[[1,1]],LSN+1},PlotStyle->{Directive[Red,Dashed],Directive[RGBColor[0.8,0.8,0],Dashed]}]

,PlotRange->Automatic,AxesLabel->{"集数","时间"},ImageSize->Full]
(*]],2]]*)
,TrackedSymbols:>{Expected}
]

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])]},
{Join[{"分钟/集",NumberForm[N[TMfoF] ,{10,1}],NumberForm[N[TMfoF] ,{10,1}],NumberForm[N[60*(InData[[-1,2]]-InData[[-2,2]])/(InData[[-1,1]]-InData[[-2,1]])] ,{10,1}]},StringForm["``~``",NumberForm[N[60*#[[2]]],{10,1}],NumberForm[N[60*#[[1]]],{10,1}]]&/@(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]]*)
,TrackedSymbols:>{Expected}
]

EndTime=AbsoluteTime[];
Row[{"总体耗时(不准):",IntegerPart[1000*(EndTime-BeginTime)],"ms"}]

环境是  Wolfram Research Mathematica v8.0.4.0

输出结果示例:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值