covariance

Defining a function that calculates the covariance-matrix of a correlation-matrix

允我心安 提交于 2019-12-03 16:38:48
I have some problems with the transformation of a matrix and the names of the rows and columns. My problem is as follows: As input-matrix I have a (symmetric) correlation matrix like this one: The correlation-vector is given by the values of the lower triangular matrix: Now, I want to compute the variance-covariance-matrix of the these correlations, which are approximately normally distributed with the variance-covariance-matrix : The variances can be approximated by -> N is the sample size (in this example N = 66) The covariances can be approximated by For example the covariance between r_02

How do I convert from List<?> to List<T> in Java using generics?

烂漫一生 提交于 2019-12-03 15:58:00
问题 In Java, how do I convert List<?> to List<T> using a general purpose method so that I can replace patterns like the following with a single method call: List untypedList = new ArrayList(); // or returned from a legacy method List<Integer> typedList = new ArrayList<Integer>(); for (Object item: untypedList) typedList.add((Integer)item); Note that the above code does not generate any type-safety warnings and, ideally, your solution shouldn't generate any such warnings, either. Will the

Covariance and Contravariance - Just different mechanisms for invoking guaranteed base class behavior?

陌路散爱 提交于 2019-12-03 13:52:01
I'm having a struggle understanding these two concepts. But I think after many videos and SO QA's, I have it distilled down to its simplest form: Covariant - Assumes a sub-type can do what its base-type does. Contravariant - Assumes you can treat a sub-type the same way you would treat its base-type. Supposing these three classes: class Animal { void Live(Animal animal) { //born! } void Die(Animal animal) { //dead! } } class Cat : Animal { } class Dog : Animal { } Covariant Any animal can do what animals do. Assumes a sub-type can do what its base-type does. Animal anAnimal = new Cat();

Interfaces inheritance in C#

吃可爱长大的小学妹 提交于 2019-12-03 11:59:25
I'm trying to overrun quite big (for me) problem that I came across while writing my application. Look at this, please (I will try to shorten the code for simplicity): I have root interface called IRepository<T> . Next, IBookRepository : IRepository<Book> Next, concrete class that implements it: BookRepository : IBookRepository In the RepositoryManager class I declared private IRepository<IRepoItem> currentRepo; IRepoItem is an interface that is implemented by Book class. Now, when I try to do something like this: currentRepo = new BookRepository(); VisualStudio gives error message: Cannot

How to determine type parameter's variance?

纵然是瞬间 提交于 2019-12-03 11:36:27
Inspired by Real-world examples of co- and contravariance in Scala I thought a better question would be: When designing a library, are there a specific set of questions you should ask yourself when determining whether a type parameter should be covariant or contravariant? Or should you make everything invariant and then change as needed? Well, simple, does it make sense? Think of Liskov substitution. Co-variance If A <: B , does it make sense to pass a C[A] where a C[B] is expected? If so, make it C[+T] . The classic example is the immutable List , where a List[A] can be passed to anything

The pooled covariance matrix of TRAINING must be positive definite

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I know this question has already been asked a couple of times, but I couldn't find a solution to my problem. I don't have more variables than observations and I don't have NAN values in my matrix. Here's my function: function [ ind , idx_ran ] = fselect ( features_f , class_f , dir ) idx = linspace ( 1 , size ( features_f , 2 ), size ( features_f , 2 )); idx_ran = idx (:, randperm ( size ( features_f , 2 ))); features_t_ran = features_f (:, idx_ran ); % randomize colums len = length ( class_f ); r = randi ( len , [ 1 , round ( len

Shouldn't ILookup<TKey, TElement> be (declared) covariant in TElement?

烂漫一生 提交于 2019-12-03 10:01:25
The definition System.Linq.ILookUp reads interface ILookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable { int Count { get; } IEnumerable<TElement> this[TKey key] { get; } bool Contains(TKey key); } Since IEnumerable is covariant in IGrouping<TKey, TElement>, IGrouping<TKey, TElement> is covariant in TElement and the interface only exposes TElement as a return type, I would assume that ILookup is also covariant in TElement. Indeed, the definition interface IMyLookup<TKey, out TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable { int Count { get; }

Calculating Mahalanobis distance with C#

匿名 (未验证) 提交于 2019-12-03 09:17:17
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to calculate the mahalanobis distance with c#. I can't find any real good examples online and I'm new to C#. I am especially having trouble getting the covariance matrix to run right. Any help would be appreciated. Thanks! using System ; using System . Collections . Generic ; using System . Linq ; using System . Text ; using System . Threading . Tasks ; using MathNet . Numerics . LinearAlgebra . Double ; namespace MahalanobisDistance { class Program { static void Main ( string [] args ) { Program p = new Program ();

Covariance vs. contravariance with respect to class inheritance

风流意气都作罢 提交于 2019-12-03 08:05:57
What is the meaning of the concepts 'covariance' and 'contravariance'? Given 2 classes, Animal and Elephant (which inherits from Animal ), my understanding is that you would get a run-time errors if you try and put an Elephant into an array of Animals, and this happens because Elephant is "bigger" (more specific) than Animal. But could you place an Animal into an array of Elephant, seeing how Elephant is guaranteed to contain the Animal properties? You have it backwards. You can add an Elephant to an Animal array because it is an Animal, and it's guaranteed to have all of the methods an Animal

.NET equivalent for Java bounded wildcard (IInterf<?>)?

社会主义新天地 提交于 2019-12-03 07:39:05
I'm stuck trying to translate some Java code that uses (bounded) wildcard generics to C#. My problem is, Java seems to allow a generic type to be both covariant and contravariant when used with a wildcard. [This is a spin-off from a previous question dealing with a simpler case of bounded-wildcards] Java - works: class Impl { } interface IGeneric1<T extends Impl> { void method1(IGeneric2<?> val); T method1WithParam(T val); } interface IGeneric2<T extends Impl> { void method2(IGeneric1<?> val); } abstract class Generic2<T extends Impl> implements IGeneric2<T> { // !! field using wildcard