covariance

Why was IEnumerable<T> made covariant in C# 4?

那年仲夏 提交于 2019-12-17 08:33:26
问题 In earlier versions of C# IEnumerable was defined like this: public interface IEnumerable<T> : IEnumerable Since C# 4 the definition is: public interface IEnumerable<out T> : IEnumerable Is it just to make the annoying casts in LINQ expressions go away? Won't this introduce the same problems like with string[] <: object[] (broken array variance) in C#? How was the addition of the covariance done from a compatibility point of view? Will earlier code still work on later versions of .NET or is

Typing a “camel caser” in Flow: variance issues?

[亡魂溺海] 提交于 2019-12-14 03:57:40
问题 try flow link I've been messing around with typing a "camel caser" function (one that consumes JSON and camel cases its keys). I've run into a few issues along the way, and I'm curious if y'all have any suggestions. A camel caser never changes the shape of its argument, so I would like to preserve the type of whatever I pass in; ideally, calling camelize on an array of numbers would return another array of numbers, etc. I've started with the following: type JSON = null | string | number |

Create correlated variables following various distributions

一曲冷凌霜 提交于 2019-12-14 03:48:39
问题 Question In R, I would like to create n variables of length L which relationship is given by a correlation matrix called cor_matrix . The important point is that the n variables may follow different distributions (including continuous vs discrete distributions). Related posts how-to-generate-sample-data-with-exact-moments generate-a-random-variable-with-a-defined-correlation-to-an-existing-variable r-constructing-correlated-variables Modified from the third post listed above, the following is

Why does a type conversion not work in Java [duplicate]

余生颓废 提交于 2019-12-13 15:41:28
问题 This question already has answers here : Is List<Dog> a subclass of List<Animal>? Why are Java generics not implicitly polymorphic? (17 answers) Closed 5 years ago . I`m wondering why this conversion is not working: ArrayList<Song> arrayList =new ArrayList<MediaItem>(); I may have to add that Song extends MediaItem. I think this conversion should work because Song has the ability to store all the information form MediaItem. So no information is lost. Does anyone have an explanation for me?

Matlab: Calculating Correlation of time series

落爺英雄遲暮 提交于 2019-12-13 08:22:56
问题 The time series model is expressed as y(t) = 0.5 + 0.3y(t-1) + n(t) where n(t) = 0.1*randn(500,1) for t=1,2,...,500 Slides contain the Correlation and covariance matrix. The formula for correlation is: E[y(t)*y(t)^T] which can be invoked by using xcorr . I would like to know how one can calculate the individual Correlation matrix for its lagged version E[y(t-1)*y(t-1)^T] without using the inbuilt commands so that I can finally implement the following expression trace([E[y(t-1)*y(t-1)']]^-1)

How is covariance implemented internally in numpy?

百般思念 提交于 2019-12-13 07:54:48
问题 This is the definition of a covariance matrix. http://en.wikipedia.org/wiki/Covariance_matrix#Definition Each element in the matrix, except in the principal diagonal, (if I am not wrong) simplifies to E(x_{i} * x_{j}) - mean(i)*mean(j) where i and j are the row number and column number of the covariance matrix. From the numpy documentation, x = np.array([[0, 2], [1, 1], [2, 0]]).T x array([[0, 1, 2], [2, 1, 0]]) np.cov(x) array([[ 1., -1.], [-1., 1.]]) The first row i.e [0, 1, 2] corresponds

R superimposing bivariate normal density (ellipses) on scatter plot

徘徊边缘 提交于 2019-12-13 05:49:40
问题 There are similar questions on the website, but I could not find an answer to this seemingly very simple problem. I fit a mixture of two gaussians on the Old Faithful Dataset: if(!require("mixtools")) { install.packages("mixtools"); require("mixtools") } data_f <- faithful plot(data_f$waiting, data_f$eruptions) data_f.k2 = mvnormalmixEM(as.matrix(data_f), k=2, maxit=100, epsilon=0.01) data_f.k2$mu # estimated mean coordinates for the 2 multivariate Gaussians data_f.k2$sigma # estimated

How to reflect an interfaced type<t> at runtime

匆匆过客 提交于 2019-12-13 03:54:24
问题 I have multiple data-points and an associated data-processor for each. public interface IDataPointProcessor<T> where T : DataPointInputBase { DataPointOutputBase GetOutput(T input); } I load a list of data points from a file and wish to process them using its single associated processor. foreach (DataPointInputBase item in input.DataPoints) { //assuming item coming in is of type 'X' how do I get correct processor var type = typeof(IDataPointProcessor<X>); var types = AppDomain.CurrentDomain

how to solve type constraint mismatch, C# to F#

本小妞迷上赌 提交于 2019-12-13 02:56:28
问题 I'm trying to implement some C# code as F# for a p2p application.. I must admit I don't have full understanding of the p2p implementation and I hope it is irrelevant for fixing the type problem.. All of the p2p library is implemented in C#. The C# implementation: public class TestMessage : Message { public string Text { get; set; } } ... var p = new Peer(); p.Subscribe(new Subscription<TestMessage> { Callback = x => Console.WriteLine(x.Text), }); The basic idea is that the 'p' peer now

Scala - Covariance

妖精的绣舞 提交于 2019-12-13 01:59:12
问题 According to covariance definition: Q[+B] means that Q can take any class, but if A is a subclass of B, then Q[A] is considered to be a subclass of Q[B]. Let's see the following example: trait SomeA trait SomeB extends SomeA trait SomeC extends SomeB case class List1[+B](elements: B*) val a = List1[SomeA](new SomeA{},new SomeB{}) val b = List1[SomeB](new SomeB{},new SomeC{}) Everything is fine, but I don't see why List1[SomeB] is a subclass of List1[SomeA] , or in other words why b is a