A Lower bound on the sum of Bernoulli random variables given a constraint on its distribution

Given a set of Bernoulli random variables $ x_1, \dots, x_n$ (not necessarily identical) with $ X= \sum_{0<i\leq n} x_i$ , I am intrested in finding a lower-bound for $ \frac{\mathbb{E} [ \min (X,k) ]}{\mathbb{E} [X]}$ in terms of $ k$ and $ \alpha$ where $ \alpha > \Pr[X>k]$ . For example, I want to show that this ratio is a large enough constant for $ \alpha=0.2$ and $ k=4$ .

How to generate a random number within a range only once?

I want to randomize numbers in a range between x and y. The problem is, while the random numbers DO get generated, Excel generates the numbers again, each time I make a change in the spreadsheet.

The purpose of this question is for the sake of generating realistic-looking ID Numbers, basically, for showing a group of students how to generate a range of ID numbers in Excel for a Mail Merge, later on. However, I don’t want them to panic, so, I want to make the Generated Numbers be generated only once. For instance, let’s say that =RANDBETWEEN(20,45) generates 31 for one cell, I want that particular cell to retain that value. In addition, I also want to demonstrate to students who want to go one step further, how to insert a string prior to the Numbers. For example, “Case: ” (without quotes), followed by the generated value. Some students even asked how to add multiple generated numbers, separated by dashes.

The code I use: =RANDBETWEEN(20,45) .

As mentioned, I only want the numbers to be generated once. Instead, every time I modify the spreadsheet, the values change.

Random Access Machines with only addition, multiplication, equality

The literature is fairly clear that unit-cost RAMs with primitive multiplication are unreasonable, in that they

  1. cannot be simulated by Turing machines in polynomial time
  2. can solve PSPACE-complete problems in polynomial time

However, all of the references I can find on this topic (Simon 1974, Schonhage 1979) also involve boolean operations, integer division, etc.

Do there exist any results for the “reasonableness” of RAMs that only have addition, multiplication, and equality? In other words, which do not have boolean operations, truncated integer division, truncated subtraction, etc?

One would think that such RAMs are still quite “unreasonable.” The main red flag is that they enable the generation of exponentially large integers in linear time, and due to the convolution-ish effects of multiplication, this can get particularly complex. However, I cannot actually find any results showing that this allows for any sort of “unreasonable” result (exponential speedup of Turing machine, unreasonable relationship to PSPACE, etc).

Does the literature have any results on this topic?

Are REST Methods Which Return Dynamically Generated Random Data Safe

Is a REST method which returns dynamically generated random data each time that it is accessed considered safe?

According to RFC 2616 (emphasis mine):

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered “safe”. This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.

My understanding from this is that the method should be considered safe as the only action is retrieval. The state of the server is not changing with multiple calls (though the result may be different) as any side effects generated would be the same (such as logging that the endpoint was accessed).

I’m not sure if this is the case though as there is no true resource being accessed since the data is generated dynamically. I also could be misunderstanding the concepts of safe methods, idempotence, and how these concepts relate to REST APIs. Any information is very much appreciated!

Algorithm for generating random incrementing numbers up to a limit

I’m trying to write a code to generate incremental sequences of numbers such as:

0 + 1 + 3 + 5 + 1 = 9  0 + 5 + 1 + 1 + 1 = 8  0 + 1 + 1 + 2 + 1 = 5 

I have 3 constrains:

1) I need to have limited number of addends (here it is =5)

2) final sum must be smaller than certain limit ( here limit is <9)

3) addends must be random

As for now, I generate sequences randomly and select only suitable ones. For 2-digit numbers and for long sequences (>8) my algorithm takes significant time.

Is there a better algorithm for such problem?

As least could you tell me, what branch of CS is studying such problems?

UPDATE (algorith):

0) array = [0,]; // initial array 1) if sum(array) < 99, countinue 2) generate random number in [1..99], let's say rand = 24 3) rand = array[-1] + rand // add random number to last value of array 4) array.push(rand) // add the random number to array 5) goto 1) 6) if length(array) < 5, goto 0) // 5 is desired sequence lenght 

Probability of a random collection of subsets being a cover

Consider the set $ [n]=\{1,2,\ldots,n\}$ . Suppose for each set $ A\subseteq [n]$ I have a $ p_A \in [0,1]$ . I now create a random collection $ \mathcal{W}\subseteq\mathcal{P}([n])$ of subsets of $ [n]$ by including each $ A$ with probability $ p_A$ , independently. What is the probability that their union covers $ [n]$ , that is, that $ $ \bigcup_{W\in\mathcal{W}} W = [n]$ $

This seems like a problem that absolutely has been considered before — it’s easy to state and seems natural — and the answer should “just” be some suitably symmetric multivariate polynomial. Unfortunately, I can’t figure it out on my own, and my google-fu hasn’t availed me either.

Random matrix with given singular value distribution

Let $ X\in\mathbb{R}^{n\times n}$ be a random matrix defined in the following way: $ $ X=U\Sigma V^T$ $ where $ U,V$ are iid uniformly distributed on $ O(n)$ , $ \Sigma=diag\{\sigma_1,…,\sigma_n\}$ and $ (\sigma_1,…,\sigma_n)$ have joint density $ f(\sigma_1,…,\sigma_n)$ with respect to the Lebesgue measure on $ \mathbb{R}^n$ . Moreover, we assume $ f$ is invariant under permutation of coordinates and change of sign of each coordinate.

Now the question is, what is the density of $ X$ with respect to the Lebesgue measure on $ \mathbb{R}^{n\times n}$

Generating random sparse matrix

My goal is to generate a large sparse matrix with majority (~99%) zeros and ones. Ideally, I would be working with 10,000 rows and 10,000,000 columns. Additionally, each column is generated as a sequence of Bernoulli samples with a column-specific probability. So far, I’ve implemented 3 ways to generate the data:

Function 1

Creating basic dense matrix of 0/1:

spMat_dense <- function(ncols,nrows,col_probs){   matrix(rbinom(nrows*ncols,1,col_probs),          ncol=ncols,byrow=T) } 

Function 2

Using Rcpp:

#include <RcppArmadillo.h>  // [[Rcpp::depends(RcppArmadillo)]]  using namespace std; using namespace Rcpp; using namespace arma;  // [[Rcpp::export]] arma::sp_mat spMat_cpp(const int& ncols, const int& nrows, const NumericVector& col_probs){    IntegerVector binom_draws = no_init(nrows);   IntegerVector row_pos;   IntegerVector col_pos;   int nz_counter=0;    //Generate (row,cell)-coordinates of non-zero values   for(int j=0; j<ncols; ++j){     binom_draws = rbinom(nrows,1,col_probs[j]);     for(int i=0; i<nrows; ++i){       if(binom_draws[i]==1){          row_pos.push_back(i);         col_pos.push_back(j);         nz_counter += 1;       }     }   }    //Create a 2 x N matrix - indicates row/col positions for N non-zero entries   arma::umat loc_mat(2,nz_counter);    for(int i=0;i<nz_counter; ++i){     loc_mat(0,i) = row_pos[i];     loc_mat(1,i) = col_pos[i];   }    IntegerVector x_tmp = rep(1,nz_counter);   arma::colvec x = Rcpp::as<arma::colvec>(x_tmp);    //sparse matrix constructor   arma::sp_mat out(loc_mat,x);   return out; } 

Function 3

Using dgCMatrix construction in Matrix package:

spMat_dgC <- function(ncols,nrows,col_probs){   #Credit to Andrew Guster (https://stackoverflow.com/a/56348978/4321711)   require(Matrix)   mat <- Matrix(0, nrows, ncols, sparse = TRUE)  #blank matrix for template   i <- vector(mode = "list", length = ncols)     #each element of i contains the '1' rows   p <- rep(0, ncols)                             #p will be cumsum no of 1s by column   for(r in 1:nrows){     row <- rbinom(ncols, 1, col_probs)            #random row     p <- p + row                                 #add to column identifier     if(any(row == 1)){       for (j in which(row == 1)){         i[[j]] <- c(i[[j]], r-1)                 #append row identifier       }     }   }   p <- c(0, cumsum(p))                           #this is the format required   i <- unlist(i)   x <- rep(1, length(i))   mat@i <- as.integer(i)   mat@p <- as.integer(p)   mat@x <- x   return(mat) } 

Benchmarking

ncols = 100000 nrows = 1000 col_probs = runif(ncols, 0.001, 0.002)  microbenchmark::microbenchmark(generate_SpMat1(ncols=ncols,nrows=nrows,col_probs=col_probs),                                generate_SpMat2(ncols=ncols,nrows=nrows,col_probs = col_probs),                                generate_spMat(ncols=ncols,nrows=nrows,col_probs=col_probs),                                times=5L)  Unit: seconds                                                           expr       spMat_dense(ncols = ncols, nrows = nrows, col_probs = col_probs)  spMat_cpp(ncols = ncols, nrows = nrows, col_probs = col_probs)      spMat_dgC(ncols = ncols, nrows = nrows, col_probs = col_probs)        min        lq      mean   median        uq       max neval   6.527836  6.673515  7.260482  7.13241  7.813596  8.155053     5  56.726238 57.038976 57.841693 57.24435 58.325564 59.873333     5   6.541939  6.599228  6.938952  6.62452  7.402208  7.526867     5 

Interestingly, my Rcpp code is not as optimal as I thought it would be. I’m not entirely sure why it’s not as efficient as the basic, dense construction. The advantage however in the Rcpp and dgCMatrix construction is that they don’t create a dense matrix first. The memory used is much less:

ncols = 100000 nrows = 1000 col_probs = runif(ncols, 0.001, 0.002)  mat1 <- spMat_dense(ncols=ncols,nrows=nrows,col_probs=col_probs) mat2 <- spMat_cpp(ncols=ncols,nrows=nrows,col_probs = col_probs) mat3 <- spMat_dgC(ncols=ncols,nrows=nrows,col_probs=col_probs)  object.size(mat1) object.size(mat2) object.size(mat3)  > object.size(mat1) 400000216 bytes > object.size(mat2) 2199728 bytes > object.size(mat3) 2205920 bytes 

Question

What is it about my Rcpp code that makes it slower than the other two? Is it possible to optimize or is the well-written R code with dgCMatrix as good as it gets?

#Name? Error in Random Cells in SharePoint List

I have a custom list in SharePoint, with this formula in a caculated field.

=IF(QC_TimeStamp=””,””,CONCATENATE(TEXT(HOUR(QC_TimeStamp-Created_Modified),”#”),” Hr(s) “,TEXT(MINUTE(QC_TimeStamp-Created_Modified),”#”),” Min(s)”))

Some rows surfaces the correct time stamp and some rows return “#Name?”. Is there a way to fix the cells that are returning the error?

Modify string that stored in clipborad depending on random value

I wrote simple program, that will make string ‘noisy’ if clipboard contains one. What disappoints me, that i should manually check what i got from getClipboardString — in the Nothing case we just simply returning from program, otherwise we modifying string. Is there a better way to do this kind of check?

import Data.Char (toUpper) import System.Random (randomIO) import System.Clipboard (setClipboardString, getClipboardString) import Control.Monad (join)  main :: IO () main = do   join $   fmap (test doNoise) getClipboardString  where  test :: (String -> IO ()) -> (Maybe String) -> IO ()  test _ Nothing = return ()  test f (Just s) = f s   doNoise :: String -> IO ()  doNoise s = do   capsed <- (sequence $   map randCap s)   setClipboardString capsed   randCap :: Char -> IO Char  randCap x = fmap ($   x) $   fmap choice (randomIO :: IO Bool)   choice :: Bool -> (Char -> Char)  choice x = if x then toUpper else id