covariance

Contravariance vs Covariance in Scala

跟風遠走 提交于 2019-12-03 06:10:12
问题 I just learned Scala. Now I am confused about Contravariance and Covariance. From this page, I learned something below: Covariance Perhaps the most obvious feature of subtyping is the ability to replace a value of a wider type with a value of a narrower type in an expression. For example, suppose I have some types Real , Integer <: Real , and some unrelated type Boolean . I can define a function is_positive :: Real -> Boolean which operates on Real values, but I can also apply this function

Type Members and Covariance

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:56:48
I guess, "type variance annotations" ( + and - ) cannot be applied to "type members". In order to explain it to myself I considered the following example abstract class Box {type T; val element: T} Now if I want to create class StringBox I have to extend Box : class StringBox extends Box { type T = String; override val element = ""} So I can say that Box is naturally covariant in type T . In other words, the classes with type members are covariant in those types. Does it make sense ? How would you describe the relationship between type members and type variance ? psp Box is invariant in its

PCA Dimensionality Reduction

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to perform PCA reducing 900 dimensions to 10. So far I have: covariancex = cov(labels); [V, d] = eigs(covariancex, 40); pcatrain = (trainingData - repmat(mean(traingData), 699, 1)) * V; pcatest = (test - repmat(mean(trainingData), 225, 1)) * V; Where labels are 1x699 labels for chars (1-26). trainingData is 699x900, 900-dimensional data for the images of 699 chars. test is 225x900, 225 900-dimensional chars. Basically I want to reduce this down to 225x10 i.e. 10 dimensions but am kind of stuck at this point. 回答1: The covariance

How to use eigenvectors obtained through PCA to reproject my data?

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using PCA on 100 images. My training data is 442368x100 double matrix. 442368 are features and 100 is number of images. Here is my code for finding the eigenvector. [ rows, cols] = size(training); maxVec=rows; maxVec=min(maxVec,rows); train_mean=mean(training,2); A=training-train_mean*ones(1,cols); A=A'*A; [evec,eval]=eig(A); [eval ind] = sort(-1*diag(eval)); evec= evec(:, ind(1:100)); Now evec is an eigenvector matrix of order of 100x100 double and now I have got 100 eigenvectors sorted. Questions: Now, if I want to transform my

Getting standard errors on fitted parameters using the optimize.leastsq method in python

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a set of data (displacement vs time) which I have fitted to a couple of equations using the optimize.leastsq method. I am now looking to get error values on the fitted parameters. Looking through the documentation the matrix outputted is the jacobian matrix, and I must multiply this by the residual matrix to get my values. Unfortunately I am not a statistician so I am drowning somewhat in the terminology. From what I understand all I need is the covariance matrix that goes with my fitted parameters, so I can square root the diagonal

Casting List&lt;T&gt; - covariance/contravariance problem

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given the following types: public interface IMyClass { } public class MyClass : IMyClass { } I wonder how can I convert a List<MyClass> to a List<IMyClass> ? I am not completely clear on the covariance/contravariance topics, but I understand that I cannot just plainly cast the List because of that. I could come up with this trivial solution only; lacking any elegance, wasting resources: ... public List<IMyClass> ConvertItems(List<MyClass> input) { var result = new List<IMyClass>(input.Count); foreach (var item in input) { result.Add(item); }

Problem understanding covariance contravariance with generics in C#

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:06:44
问题 I can't understand why the following C# code doesn't compile. As you can see, I have a static generic method Something with an IEnumerable<T> parameter (and T is constrained to be an IA interface), and this parameter can't be implicitly converted to IEnumerable<IA> . What is the explanation? (I don't search for a workaround, just to understand why it doesn't work). public interface IA { } public interface IB : IA { } public class CIA : IA { } public class CIAD : CIA { } public class CIB : IB

Covariance matrix from np.polyfit() has negative diagonal?

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Problem: the cov=True option of np.polyfit() produces a diagonal with non-sensical negative values. UPDATE: after playing with this some more, I am really starting to suspect a bug in numpy ? Is that possible? Deleting any pair of 13 values from the dataset will fix the problem. I am using np.polyfit() to calculate the slope and intercept coefficients of a dataset. A plot of the values produces a very linear (but not perfectly) linear graph. I am attempting to get the standard deviation on these coefficients with np.sqrt(np.diag(cov)) ;

Sample from multivariate normal/Gaussian distribution in C++

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been hunting for a convenient way to sample from a multivariate normal distribution. Does anyone know of a readily available code snippet to do that? For matrices/vectors, I'd prefer to use Boost or Eigen or another phenomenal library I'm not familiar with, but I could use GSL in a pinch. I'd also like it if the method accepted nonnegative -definite covariance matrices rather than requiring positive-definite (e.g., as with the Cholesky decomposition). This exists in MATLAB, NumPy, and others, but I've had a hard time finding a ready

Problem understanding covariance contravariance with generics in C#

谁都会走 提交于 2019-12-02 15:41:07
I can't understand why the following C# code doesn't compile. As you can see, I have a static generic method Something with an IEnumerable<T> parameter (and T is constrained to be an IA interface), and this parameter can't be implicitly converted to IEnumerable<IA> . What is the explanation? (I don't search for a workaround, just to understand why it doesn't work). public interface IA { } public interface IB : IA { } public class CIA : IA { } public class CIAD : CIA { } public class CIB : IB { } public class CIBD : CIB { } public static class Test { public static IList<T> Something<T>