covariance

Compute covariance matrix on our own (without using `cov`)

徘徊边缘 提交于 2019-12-13 00:37:19
问题 I am following a tutorial about covariance matrices that could be found here: http://stats.seandolinar.com/making-a-covariance-matrix-in-r/ It includes the following steps: #create a dataframe a <- c(1,2,3,4,5,6) b <- c(2,3,5,6,1,9) c <- c(3,5,5,5,10,8) d <- c(10,20,30,40,50,55) e <- c(7,8,9,4,6,10) #create matrix from vectors M <- cbind(a,b,c,d,e) M_mean <- matrix(data=1, nrow=n) %*% cbind(mean(a),mean(b),mean(c),mean(d),mean(e)) k <- ncol(M) #number of variables n <- nrow(M) #number of

WPF How to cast ListBox.ItemsSource into ObservableCollection<some dynamic type>

拜拜、爱过 提交于 2019-12-12 21:03:51
问题 I have written a Behavior which allows to reorder a ListBox. To work properly the ListBox's ItemsSource has to be an ObservableCollection<...>, so I can call the Move(from,to)-method. My problem is: How can I cast the ListBox.ItemsSource into a ObservableCollection. I already tried: ObservableCollection<object> test = listBox.ItemsSource as ObservableCollection<object>; which does not work, because ObservableCollection doesn't support covariance. 回答1: Since you know the method you'd like to

Conversion error with generic covariance

自古美人都是妖i 提交于 2019-12-12 19:23:39
问题 I got the following code and it gives me compile error: cannot convert from 'UserQuery.SomeClass<int>' to UserQuery.Interface<System.IConvertible>' the code: void Main() { List<Interface<IConvertible>> values = new List<Interface<IConvertible>>(); values.Add(new SomeClass<int>() {Value = 50 }); } interface Interface<out T> where T : IConvertible { T Value { get; } } class SomeClass<T> : Interface<T> where T : IConvertible { public T Value { get; set; } } However, trying to add SomeClass

covariance structure for multilevel modelling

旧街凉风 提交于 2019-12-12 14:57:05
问题 I have a multilevel repeated measures dataset of around 300 patients each with up to 10 repeated measures predicting troponin rise. There are other variables in the dataset, but I haven't included them here. I am trying to use nlme to create a random slope, random intercept model where effects vary between patients, and effect of time is different in different patients. When I try to introduce a first-order covariance structure to allow for the correlation of measurements due to time I get

How is IEnumerable<T> Contra-variant?

一曲冷凌霜 提交于 2019-12-12 11:22:53
问题 This post (http://blogs.msdn.com/b/brada/archive/2005/01/18/355755.aspx) says IEnumerable<T> is Contra-variant. However type T is co-variant because it is an out parameter. So in what context is IEnumerable<T> Contra-variant ?? Hope I am not confusing! Thanks for the answers in advance! 回答1: IEnumerable isn't contra-variant. It's covariant. From MSDN (IEnumerable<(Of <(T>)>) Interface) we have that: Type Parameters out T The type of objects to enumerate. This type parameter is covariant .

interface covariance issue

谁说胖子不能爱 提交于 2019-12-12 10:59:16
问题 The following code sample: interface I<out T> where T : class, I<T> { T GetT(); } interface J : I<J> { } abstract class B<T> : I<T> where T : B<T> { T I<T>.GetT() { return null; } } class C : B<C>, J { } fails to compile (under VS2010 with SP1) with the following error: Error 4 'C' does not implement interface member 'I<J>.GetT()' However, C does implement (through its base B<C>) I<C>, which, due to I being declared covariant, should capture I<J> as well (as C : J). Is this a compiler bug? If

Why isn't `curve_fit` able to estimate the covariance of the parameter if the parameter fits exactly?

和自甴很熟 提交于 2019-12-12 08:21:42
问题 I don't understand curve_fit isn't able to estimate the covariance of the parameter, thus raising the OptimizeWarning below. The following MCVE explains my problem: MCVE python snippet from scipy.optimize import curve_fit func = lambda x, a: a * x popt, pcov = curve_fit(f = func, xdata = [1], ydata = [1]) print(popt, pcov) Output \python-3.4.4\lib\site-packages\scipy\optimize\minpack.py:715: OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning) [ 1.] [

Error: Covariant type A occurs in contravariant position

柔情痞子 提交于 2019-12-12 08:00:48
问题 I was trying to write an immutable Matrix[A] class. I want the class to be covariant on A but when I put + in front of A compiler starts complaining about some operations in the class. Following is a relevant subset of my Matrix class (The actual class is some 5 times bigger than the following subset): class Matrix[+A] private(val contents: Vector[Vector[A]])(implicit numericEv: Numeric[A]) extends ((Int, Int) => A) with Proxy { import numericEv._ import Prelude._ // delegate `equals` and

Why can't I substitute a slice of one type for another in Go?

荒凉一梦 提交于 2019-12-12 05:48:54
问题 I'm trying to understand Go's type conversion rules. Say we have these interfaces: type woofer interface { woof() } type runner interface { run() } type woofRunner interface { woofer runner } and to satisfy the interfaces we have a dog type: type dog struct{} func (*dog) run() {} func (*dog) woof() {} These two functions are using the interfaces: func allWoof(ws []woofer) {} func oneWoof(w woofer) {} To use these methods I can write the following: dogs := make([]woofRunner, 10) oneWoof(dogs[0

How can members of IEnumerable<T> be modified?

最后都变了- 提交于 2019-12-12 04:22:15
问题 In an earlier question about generic variance, I was informed that members of IEnumerable<T> can be modified. How can that be done and, seeing as variance violations arise when a covariant type can be modified, how then can IEnumerable<T> be covariant on T ? 回答1: You have to distinguish modifying the sequence from modifying the elements of it. You can modify elements without any problems, since you can't modify the type of the object by using properties and functions on it. And thus, this is