mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-08-19 12:30:46 +08:00
added initial studentT output
This commit is contained in:
@@ -9,6 +9,7 @@ from pts.feature import (
|
||||
time_features_from_frequency_str,
|
||||
)
|
||||
from pts.model import PTSEstimator
|
||||
from pts.modules import DistributionOutput, StudentTOutput
|
||||
|
||||
|
||||
class DeepAREstimator(PTSEstimator):
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from pts.modules.distribution_output import ArgProj
|
||||
from pts.modules.lambda_layer import LambdaLayer
|
||||
from .distribution_output import ArgProj, Output, DistributionOutput, StudentTOutput
|
||||
from .lambda_layer import LambdaLayer
|
||||
|
||||
@@ -4,7 +4,8 @@ from typing import Callable, Dict, Optional, Tuple
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from torch.distributions import Distribution, TransformedDistribution, AffineTransform
|
||||
import torch.nn.functional as F
|
||||
from torch.distributions import *
|
||||
|
||||
from .lambda_layer import LambdaLayer
|
||||
|
||||
@@ -73,3 +74,14 @@ class DistributionOutput(Output):
|
||||
else:
|
||||
distr = self.distr_cls(*distr_args)
|
||||
return TransformedDistribution(distr, [AffineTransform(loc=0, scale=scale)])
|
||||
|
||||
|
||||
class StudentTOutput(DistributionOutput):
|
||||
args_dim: Dict[str, int] = {"df": 1, "loc": 1, "scale": 1}
|
||||
distr_cls: type = StudentT
|
||||
|
||||
@classmethod
|
||||
def domain_map(cls, df, loc, scale):
|
||||
scale = nn.Softplus(scale)
|
||||
df = 2.0 + nn.Softplus(df)
|
||||
return df.squeeze(-1), loc.squeeze(-1), scale.squeeze(-1)
|
||||
|
||||
Reference in New Issue
Block a user