weighted

Generate Weighted Random Boolean Matrix in Matlab

一笑奈何 提交于 2019-12-13 16:15:12
问题 I want to generate a 5x5 matrix in MatLab that is made of only 1s and 0s, however I want to be able to set the likelihood of any value being a 1. I want there to be a 90% chance any element will be a 1 rather than a 0. However I do NOT want there to just always be 90% 1s and 10% 0s. I just want this to be the more likely case. E.g. I still want it to be possible to be all 0s, or 50% 1s and 50% 0s, just very unlikely. Thank you for any help. 回答1: I've wrote a very clear and simple code to

R Loop To New Data Frame Summary Weighted

泄露秘密 提交于 2019-12-11 10:36:16
问题 I have a tall data frame as such: data = data.frame("id"=c(1,2,3,4,5,6,7,8,9,10), "group"=c(1,1,2,1,2,2,2,2,1,2), "type"=c(1,1,2,3,2,2,3,3,3,1), "score1"=c(sample(1:4,10,r=T)), "score2"=c(sample(1:4,10,r=T)), "score3"=c(sample(1:4,10,r=T)), "score4"=c(sample(1:4,10,r=T)), "score5"=c(sample(1:4,10,r=T)), "weight1"=c(173,109,136,189,186,146,173,102,178,174), "weight2"=c(147,187,125,126,120,165,142,129,144,197), "weight3"=c(103,192,102,159,128,179,195,193,135,145), "weight4"=c(114,182,199,101

Class based weighted raster aggregation

女生的网名这么多〃 提交于 2019-12-11 07:05:46
问题 Let's assume I have a raster representing land use classes in a certain resolution. I have to aggregate this raster with R to a coarser resolution and a modal value approach, in order to have the most dominating cell value in the coarser raster. This is easily achieved with m <- aggregate(r, fact = 3, fun = modal, na.rm = TRUE) However, I would like to weight the different land use classes – e.g. forest class (code 1) has a weight of 4 while water class (code 2) has a weight of 2 and street

All shortest paths for weighted graphs with networkx?

落爺英雄遲暮 提交于 2019-12-11 01:14:38
问题 I have a graph composed by two different sets of edges. The first set is made by edges of weight 1 (list 1). The second set is made by edges of weight 2 (list 2). First, I create the graph with networkx and then use add_edges_from to add list 1 and list 2. I would like to compute all the shortest paths in this weighted graph. Basically I'm looking for the analogous of "all_shortest_paths" but with weights (looks like "dijkstra" module does not allow you to know all the possible routes between

Weighted random integers

帅比萌擦擦* 提交于 2019-12-11 00:53:04
问题 I want to assign weightings to a randomly generated number, with the weightings represented below. 0 | 1 | 2 | 3 | 4 | 5 | 6 ───────────────────────────────────────── X | X | X | X | X | X | X X | X | X | X | X | X | X | X | X | X | X | | X | X | X | X | | | X | X | X | | | | X | X | | | | | X | | | | | | What's the most efficient way to do it? 回答1: @Kerrek's answer is good. But if the histogram of weights is not all small integers, you need something more powerful: Divide [0..1] into

C++. Weighted std::shuffle

我只是一个虾纸丫 提交于 2019-12-08 17:26:26
问题 Is there a way to do nice and elegant weighted shuffling using standard library? There is std::discrete_distribution . What I want is something like this: std::vector<T> data { N elements }; std::vector<int> weights { N weights }; std::shuffle(std::begin(data), std::end(data), something based on discrete distribution); 回答1: If OP intent is to shuffle a list r of items such that, given a list of weights w , the element a[i] with weight w[i] should be the first element of the random shuffle r

Weight samples if incorrect guessed in binary cross entropy

不问归期 提交于 2019-12-07 13:08:52
问题 Is there a way in keras or tensorflow to give samples an extra weight if they are incorrectly classified only. Ie. a combination of class weight and sample weight but only apply the sample weight for one of the outcomes in a binary class? 回答1: Yes, it's possible. Below you may find an example of how to add additional weight on true positives , false positives , true negatives , etc: def reweight(y_true, y_pred, tp_weight=0.2, tn_weight=0.2, fp_weight=1.2, fn_weight=1.2): # Get predictions y

Weight samples if incorrect guessed in binary cross entropy

混江龙づ霸主 提交于 2019-12-05 22:22:40
Is there a way in keras or tensorflow to give samples an extra weight if they are incorrectly classified only. Ie. a combination of class weight and sample weight but only apply the sample weight for one of the outcomes in a binary class? Yes, it's possible. Below you may find an example of how to add additional weight on true positives , false positives , true negatives , etc: def reweight(y_true, y_pred, tp_weight=0.2, tn_weight=0.2, fp_weight=1.2, fn_weight=1.2): # Get predictions y_pred_classes = K.greater_equal(y_pred, 0.5) y_pred_classes_float = K.cast(y_pred_classes, K.floatx()) # Get

Modularity calculation for weighted graphs in igraph

坚强是说给别人听的谎言 提交于 2019-12-05 20:11:49
I used the fastgreedy algorithm in igraph for my community detection in a weighted, undirected graph. Afterwards I wanted to have a look at the modularity and I got different values for different methods and I am wondering why. I included a short example, which demonstrates my problem: library(igraph) d<-matrix(c(1, 0.2, 0.3, 0.9, 0.9, 0.2, 1, 0.6, 0.4, 0.5, 0.3, 0.6, 1, 0.1, 0.8, 0.9, 0.4, 0.1, 1, 0.5, 0.9, 0.5, 0.8, 0.5, 1), byrow=T, nrow=5) g<-graph.adjacency(d, weighted=T, mode="lower",diag=FALSE, add.colnames=NA) fc<-fastgreedy.community(g) fc$modularity[3] #[1] -0.05011095 modularity(g

Adding a weighted least squares trendline in ggplot2

隐身守侯 提交于 2019-12-05 05:18:08
I am preparing a plot using ggplot2, and I want to add a trendline that is based on a weighted least squares estimation. In base graphics this can be done by sending a WLS model to abline : mod0 <- lm(ds$dMNP~ds$MNP) mod1 <- lm(ds$dMNP~ds$MNP, weights = ds$Asset) symbols(ds$dMNP~ds$MNP, circles=ds$r, inches=0.35) #abline(mod0) abline(mod1) in ggplot2 I set the argument weight in geom_smooth but nothing changes: ggplot(ds, aes(x=MNP, y=dMNP, size=Asset) + geom_point(shape=21) + geom_smooth(method = "lm", weight="Asset", color="black", show.legend = FALSE) this gives me the same plot as ggplot