/// <summary>Sets all values in a matrix to zero</summary> /// <param name='c'>a correlation matrix</param> static public void SetZero(this ICorrelationMatrix c) { int size = c.NumberOfRows; c.Resize(0); c.Resize(size); // TODO consider doing this without resize }
public AssetFxModel(TO_AssetFxModel transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) : this(transportObject.BuildDate, new FundingModel(transportObject.FundingModel, currencyProvider, calendarProvider)) { _assetCurves = transportObject.AssetCurves.ToDictionary(x => x.Key, x => x.Value.GetPriceCurve(currencyProvider, calendarProvider)); _assetVols = transportObject.AssetVols.ToDictionary(x => new VolSurfaceKey(x.Key, currencyProvider), y => VolSurfaceFactory.GetVolSurface(y.Value, currencyProvider)); _fixings = transportObject.Fixings?.ToDictionary(x => x.Key, x => (IFixingDictionary) new FixingDictionary(x.Value)) ?? new Dictionary <string, IFixingDictionary>(); CorrelationMatrix = transportObject.CorrelationMatrix == null?null:CorrelationMatrixFactory.GetCorrelationMatrix(transportObject.CorrelationMatrix); }
/// <summary>Sum up the correlations between a given entity and the entities in a collection</summary> /// <param name="correlation">the correlation matrix</param> /// <param name="entity_id">the numerical ID of the entity</param> /// <param name="entities">a collection containing the numerical IDs of the entities to compare to</param> /// <param name="q">score exponent</param> /// <returns>the correlation sum</returns> public static double SumUp(this ICorrelationMatrix correlation, int entity_id, ICollection <int> entities, float q = 1.0f) { double result = 0; foreach (int entity_id2 in entities) { result += Math.Pow(correlation[entity_id, entity_id2], q); } return(result); }
public static TO_CorrelationMatrix GetTransportObject(this ICorrelationMatrix matrix) { switch (matrix) { case CorrelationMatrix cm: return(cm.GetTransportObject()); case CorrelationTimeVector ctv: return(ctv.GetTransportObject()); case CorrelationMatrixCollection ctc: return(ctc.GetTransportObject()); default: throw new Exception("Unable to serialize correlation object"); } }
/// <summary>Get all entities that are positively correlated to an entity, sorted by correlation</summary> /// <param name="c">a correlation matrix</param> /// <param name="entity_id">the entity ID</param> /// <returns>a sorted list of all entities that are positively correlated to entitiy_id</returns> public static IList <int> GetPositivelyCorrelatedEntities(this ICorrelationMatrix c, int entity_id) { int num_entities = c.NumberOfRows; var result = new List <int>(); for (int i = 0; i < num_entities; i++) { if (c[i, entity_id] > 0) { result.Add(i); } } result.Remove(entity_id); result.Sort(delegate(int i, int j) { return(c[j, entity_id].CompareTo(c[i, entity_id])); }); return(result); }
void InitModel() { int num_entities = 0; switch (Correlation) { case RatingCorrelationType.BinaryCosine: correlation_matrix = new BinaryCosine(num_entities); break; case RatingCorrelationType.Jaccard: correlation_matrix = new Jaccard(num_entities); break; case RatingCorrelationType.ConditionalProbability: correlation_matrix = new ConditionalProbability(num_entities); break; case RatingCorrelationType.BidirectionalConditionalProbability: correlation_matrix = new BidirectionalConditionalProbability(num_entities, Alpha); break; case RatingCorrelationType.Cooccurrence: correlation_matrix = new Cooccurrence(num_entities); break; case RatingCorrelationType.Pearson: correlation_matrix = new Pearson(num_entities, Alpha); break; case RatingCorrelationType.RatingCosine: correlation_matrix = new RatingCosine(num_entities, Alpha); break; default: throw new NotImplementedException(string.Format("Support for {0} is not implemented", Correlation)); } if (correlation_matrix is IBinaryDataCorrelationMatrix) { ((IBinaryDataCorrelationMatrix)correlation_matrix).Weighted = WeightedBinary; } }
/// <summary>Get the k nearest neighbors of a given entity</summary> /// <param name="c">a correlation matrix</param> /// <param name="entity_id">the numerical ID of the entity</param> /// <param name="k">the neighborhood size</param> /// <returns>a sorted list containing the numerical IDs of the k nearest neighbors</returns> public static IList <int> GetNearestNeighbors(this ICorrelationMatrix c, int entity_id, uint k) { int num_entities = c.NumberOfRows; var entities = new List <int>(); for (int i = 0; i < num_entities; i++) { entities.Add(i); } entities.Remove(entity_id); entities.Sort(delegate(int i, int j) { return(c[j, entity_id].CompareTo(c[i, entity_id])); }); if (k < entities.Count) { return(entities.GetRange(0, (int)k).ToArray()); } else { return(entities.ToArray()); } }
void InitModel() { int num_entities = 0; switch (Correlation) { case RatingCorrelationType.BinaryCosine: correlation_matrix = new BinaryCosine(num_entities); break; case RatingCorrelationType.Jaccard: correlation_matrix = new Jaccard(num_entities); break; case RatingCorrelationType.ConditionalProbability: correlation_matrix = new ConditionalProbability(num_entities); break; case RatingCorrelationType.BidirectionalConditionalProbability: correlation_matrix = new BidirectionalConditionalProbability(num_entities, Alpha); break; case RatingCorrelationType.Cooccurrence: correlation_matrix = new Cooccurrence(num_entities); break; case RatingCorrelationType.Pearson: correlation_matrix = new Pearson(num_entities, Alpha); break; case RatingCorrelationType.RatingCosine: correlation_matrix = new RatingCosine(num_entities, Alpha); break; default: throw new NotImplementedException(string.Format("Support for {0} is not implemented", Correlation)); } if (correlation_matrix is IBinaryDataCorrelationMatrix) ((IBinaryDataCorrelationMatrix) correlation_matrix).Weighted = WeightedBinary; }
public CholeskyWithTime(ICorrelationMatrix correlationMatrix, IAssetFxModel model) { _matrix = correlationMatrix; _model = model; }
public Cholesky(ICorrelationMatrix correlationMatrix) { _matrix = correlationMatrix; }