How can we compute the multiplicative partition function

Question: Please how can we compute the multiplicative partition function. For example $24$, has precisely $6$ valid factorizations: $2\cdot2\cdot2\cdot3$, $2\cdot2\cdot6$, $2\cdot3\cdot4$, $2\cdot12$, $3\cdot8$, and $4\cdot6$.
Comment: I've looked at them but there's no algorithm for computing what I found is just to know the lower bound
Comment: Have you read the page and investigated the references at Wikipedia? https://en.wikipedia.org/wiki/Multiplicative_partition
Comment: Is this any help? http://stackoverflow.com/questions/8558292/how-to-find-multiplicative-partitions-of-any-integer
Comment: I didn't want to start coding an algorithm that uses a dynamic programming solution. I'm wondering if there's an efficient algorithm to compute the function.
Answer: There is a formula that depends only on the shape of the prime factorization of $n$, i.e. the exponents of the primes in the factorization. This formula is obtained with the Polya Enumeration Theorem (PET) applied to a certain repertoire. It includes the factorization into a product of one term, namely $n$.
Let $$n= p_1^{v_1} p_2^{v_2} \times \cdots \times p_q^{v_q}$$
be the prime factorization of $n$ and recall the function $\Omega(n)$ which is given by
$$\Omega(n) = \sum_{k=1}^q v_k,$$
i.e. it counts the prime factors according to their multiplicities.
The repertoire that goes into PET is given by
$$Q = -1 + \prod_{k=1}^q \sum_{v=0}^{v_k} u_{p_k}^v
= -1 + \prod_{k=1}^q \frac{u_{p_k}^{v_k+1}-1}{u_{p_k}-1}$$
which is an ordinary generating function in the set of variables $\{u_{p_k}\}.$
With these settings the value $q(n)$ of the multiplicative partition function is given by
$$q(n) = [u_{p_1}^{v_1} u_{p_2}^{v_2}\cdots u_{p_q}^{v_q}]
\sum_{m=1}^{\Omega(n)} Z(S_m)(Q),$$
where $Z(S_m)$ is the cycle index of the symmetric group acting on $m$ elements, which is computed from
$$Z(S_0) = 1 \quad \text{and}\quad Z(S_m) = \frac{1}{m} \sum_{l=1}^m a_l Z(S_{m-l}).$$
This produces the following sequence starting at $n=2$ and extending to $n=64$
$$1, 1, 2, 1, 2, 1, 3, 2, 2, 1, 4, 1, 2, 2, 5, 1, 4, 1, 4,\\
2, 2, 1, 7, 2, 2, 3, 4, 1, 5, 1, 7, 2, 2, 2, 9, 1, 2, 2, 7,\\
1, 5, 1, 4, 4, 2, 1, 12, 2, 4, 2, 4, 1, 7, 2, 7, 2, 2, 1, 11, 1, 2, 4, 11,\ldots$$
which points to OEIS A001055.
The complexity of the repertoire that goes into the cycle index is $\tau(n).$
Remark as of Tue Jan  7 00:40:27 CET 2014. This algorithm is definitely not as good as what was posted at the Math Overflow link. Please consult my second answer for a fast algorithm.
Here is the Maple code that was used to compute the above values:

with(numtheory);
with(group):
with(combinat):

pet_cycleind_symm :=
proc(n)
        option remember;

        if n=0 then return 1; fi;

        expand(1/n*add(a[l]*pet_cycleind_symm(n-l), l=1..n));
end;

pet_varinto_cind :=
proc(poly, ind)
           local subs1, subs2, polyvars, indvars, v, pot, res;

           res := ind;

           polyvars := indets(poly);
           indvars := indets(ind);

           for v in indvars do
               pot := op(1, v);

               subs1 :=
               [seq(polyvars[k]=polyvars[k]^pot,
               k=1..nops(polyvars))];

               subs2 := [v=subs(subs1, poly)];

               res := subs(subs2, res);
           od;

           res;
end;

v :=
proc(n)
        option remember;
        local fact, rep, gf, fcount, p, res;

        fact := op(2, ifactors(n));

        rep := mul(add(u[fact[k][1]]^p, p=0..fact[k][2]),
                   k=1..nops(fact));
        rep := rep-1;

        res := 0;
        for fcount to bigomega(n) do
            gf := pet_varinto_cind(rep, pet_cycleind_symm(fcount));
            gf := expand(gf);

            for p to nops(fact) do
                gf := coeff(gf, u[fact[p][1]], fact[p][2]);
            od;

            res := res+gf;
        od;

        res;
end;
Comment: Can you provide me with a C implementation please.
Answer: For the purpose of completing this discussion and providing an effective solution I am sending a dynamic-programming implementation in Maple and in Perl. This is the Maple code.
Addendum Tue Jan  7 08:05:14 CET 2014. Further optimization is possible as this statistic only depends on the shape of the factorization and not the primes, so the shape can be our key for use in memoization. The reader is invited to try this. Of course in this setup you only profit from memoization if you invoke the function at the main interface multiple times, so this is not a DP algorithm in the classic sense.

mp :=
proc(n)
    option remember;
    local rec, onef, res, f, asg, targ, t;

    if n=1 then return {}; fi;

    onef := op(2, ifactors(n))[1];

    rec := mp(n/onef[1]);
    if nops(rec) = 0 then return {[n=1]} fi;

    res := {};
    for f in rec do
        t := table(f);

        targ := onef[1];
        if type(t[targ], integer) then
            t[targ] := t[targ] + 1
        else
            t[targ] := 1;
        fi;

        res := res union {sort(op(op(t)))};

        for asg in f do
            t := table(f);

            targ := onef[1]*op(1, asg);
            if type(t[targ], integer) then
                t[targ] := t[targ]+1;
            else
                t[targ] := 1;
            fi;

            if t[op(1,asg)]>1 then
                t[op(1,asg)] := t[op(1,asg)]-1;
            else
                t[op(1,asg)] := evaln(t[op(1,asg)]);
            fi;

            res := res union {sort(op(op(t)))};
        od;
    od;

    res;
end;

It can be used to compute the number of factorizations approximately up to about $9!$, after which it slows dramatically for some reason.
To get around this problem I am also sending a Perl program that implements the DP algorithm. This has the drawback that the factorization method is naive and slow to detect large primes but it illustrates the concept especially for values with many factors that have numerous factorizations e.g. for $10^{10}$ which gives $59521$ factorizations.

#! /usr/bin/perl -w
#

sub onefact {
    my ($n) = @_;

    return 2 if $n % 2 == 0;

    my $f = 3;

    while($n % $f > 0){
        $f += 2;
    }

    return $f;
}

my %memo = ( 1 => {} );

sub mp {
    my ($n) = @_;
    return $memo{$n} if exists $memo{$n};

    my $res = {};

    my $onef = onefact($n);
    if($n/$onef == 1){
        $res->{"$n=1"} = 1;
    }
    else{
        sub tbl2str {
            my ($tref) = @_;
            my @keyl = map {
                $_ . "=" . $tref->{$_}
            } sort(keys(%$tref));

            return join('-', @keyl);
        }

        foreach my $f (keys %{mp($n/$onef)}){
            my @asigs = map {
                split(/=/);
            } split(/-/, $f);

            my (%tblsrc) = @asigs;

            my (%tbl) = @asigs;
            if(exists($tbl{$onef})){
                $tbl{$onef} = $tbl{$onef} + 1;
            }
            else{
                $tbl{$onef} = 1;
            }

            $res->{tbl2str(\%tbl)} = 1;

            for my $a (keys %tblsrc){
                %tbl = %tblsrc;

                my $targ = $onef*$a;
                if(exists($tbl{$targ})){
                    $tbl{$targ}++;
                }
                else{
                    $tbl{$targ} = 1;
                }

                if($tbl{$a}>1){
                    $tbl{$a}--;
                }
                else{
                    delete $tbl{$a};
                }

                $res->{tbl2str(\%tbl)} = 1;
            }
        }
    }

    $memo{$n} = $res;
    return $res;
}

MAIN: {
    while(my $n = shift){
        my $res = scalar(keys %{mp($n)});
        my $msize = scalar(keys %memo);
        print "$n $res [$msize]\n";
    }
}

This program is very fast and can be used to compute the number of factorizations even of large factorials, e.g. for $8!, 9!, 10!$ and $11!$ it computes in a matter of seconds the values
$$2116,11830, 70520, 425240,2787810\ldots$$
which points us to OEIS A076716. Perl took about eight minutes to compute the value for $12!.$ In spite of the naive factorization the Perl program can be used on large primes or products of them, e.g. try $104729$ or $62773913 = 7919\times 7927.$
Answer: I feel compelled to add another answer as the code from my initial effort is really quite poor and I am not only referring to the grade school factorization routine. I asked the kind folks at MaplePrimes for advice and it turns out that the multiplicative partition function was the subject of an extensive discussion there and a collaborative effort led to a simple and effective algorithm being developed. The key observation in this algorithm is that we can generate all partitions by starting with the single factor partition and calculating the two-factor, three-factor etc. partitions by repeatedly splitting the largest element into two factors and admitting the resulting partition into the new collection if both factors are at least as large as the factor at the end of the partition whose last element was split. That is all and this simple observation makes it possible to compute very large sets of multiplicative partitions quickly and effectively. The credit goes to the MaplePrimes Thread of course and to the people who participated in it. What is nice about this algorithm is that it maintains the partitions and their elements in sorted order automagically.
I am sending a Perl program that implements this simple algorithm (there is a Maple implementation including extensive commentary at the link I gave). It takes three types of arguments: a factorial produces the count of the multiplicative partition values at a range of factorials up to some maximum, a range with a central dash will process an entire range of values and a single numeric argument outputs the partitions for that argument.
Here are some examples.

$ ./mp-final.pl 40-60
7, 1, 5, 1, 4, 4, 2, 1, 12, 2, 4, 2, 4, 1, 7, 2, 7, 2, 2, 1, 11
$ ./mp-final.pl 10!
0, 1, 2, 7, 21, 98, 392, 2116, 11830, 70520
$ ./mp-final.pl 100
> 100
> 5 20
> 2 50
> 10 10
> 4 25
> 2 5 10
> 2 2 25
> 4 5 5
> 2 2 5 5
9

The chief drawback of this Perl skript is that the factorization is naive and there is no builtin for computing the number theoretic function $\Omega(n)$ giving the prime count including multiplicities.
This is the code, and improvement over the first version I hope although that is not saying much.

#! /usr/bin/perl -w
#

sub onefact {
    my ($n) = @_;

    return 2 if $n % 2 == 0;

    my $f = 3;
    my $z = int sqrt $n;

    while($n % $f > 0 && $f <= $z){
        $f += 2;
    }
    return $n if $f>$z;

    return $f;
}

my %div_memo;
sub div {
    my ($n) = @_;
    return $div_memo{$n} if exists $div_memo{$n};

    my $of = onefact($n);
    if($of == $n){
        $div_memo{$n} = [1, $n];
    }
    else{
        my $divs = [];
        push @$divs, @{div($n/$of)};

        my %seen = map { $_, 1 } @$divs;

        my $mx = scalar(@$divs);
        for(my $pos=0; $pos<$mx; $pos++){
            my $targ = $divs->[$pos]*$of;
            push @$divs, $targ if not exists $seen{$targ};
        }

        $div_memo{$n} = $divs;
    }

    return $div_memo{$n};
}

my %memo = ("1" => []);

sub mp {
    my ($n) = @_;
    return $memo{"$n"} if exists $memo{"$n"};

    my @result = ([$n]); my $m = 2;
    my ($min, $max) = (0, 0);

    while(1){
        for(my $ind = $min; $ind<=$max; $ind++){
            my $mpart = $result[$ind];

            my $spl = $#$mpart;
            my $spval = $mpart->[$spl];
            my @divs = @{ div($spval) };

            foreach my $d (@divs){
                my $q = $spval/$d;

                if($d > 1 && $d <= $q &&
                   ($spl == 0 || $d >= $mpart->[-2])){
                    my $npart = [@$mpart];

                    pop @$npart;
                    push @$npart, $d, $q;

                    push @result, $npart;
                }
            }
        }

        my $lastfact = $result[-1]; $cont = undef;
        foreach my $term (@$lastfact){
            if(scalar(@{ div($term) }) != 2){
                $cont = 1;
                last;
            }
        }

        last if not defined($cont);
        $min = $max+1; $max = $#result;
        $m++;
    }

    $memo{"$n"} = \@result;
    return \@result;
}

MAIN: {
    while(my $nstr = shift){
        if(my @int = ($nstr =~ /^(\d+)-(\d+)$/)){
            for(my $n = $int[0]; $n <= $int[1]; $n++){
                print ", " if $n>$int[0];
                print scalar(@{mp($n)});
            }
        }
        elsif (my @mx = ($nstr =~ /^(\d+)!$/)){
            for(my ($n, $p) = (1, 1); $n <= $mx[0]; $n++){
                $p *= $n;

                print ", " if $p>1;
                print scalar(@{mp($p)});
            }
        }
        elsif (my @nvals = ($nstr =~ /^(\d+)$/)){
            foreach my $ent (@{mp($nvals[0])}){
                print "> @$ent\n";
            }

            print scalar(@{mp($nvals[0])});
        }
        else{
            warn "skipping argument $nstr";
        }
    }

    print "\n";
}
Answer: Following up on some of Marko's replies, Perl does have at least two ways to compute Ω(n), assuming you are willing to use modules: scalar Math::Prime::Util::factor, and Math::Pari::bigomega.  Here is an example using modules to make simpler code.  I've also added the fcnt function from A001055 that just returns the count, which lets one calculate the factorial examples faster and with reasonable amounts of memory.
<code>
use warnings;
use strict;
use Math::Prime::Util qw/divisors fordivisors is_prime/;
use Memoize;  memoize('mp');  memoize('fcnt');
$|++;

sub fcnt {
  my($n, $m) = @_;
  return 1 if $n == 1;
  my $s = 0;
  fordivisors {
    $s += fcnt($n/$_, $_) if $_ > 1 && $_ <= $m;
  } $n;
  return $s;
}

sub mp {
  my ($n) = @_;
  return [] if $n == 1;

  my @result = ([$n]);
  my ($min, $max) = (0, 0);

  while ( scalar grep { !is_prime($_) } @{$result[-1]} ) {

    for (my $ind = $min; $ind <= $max; $ind++) {
      my @mpart = @{$result[$ind]};

      my $spval = $mpart[-1];
      my $dmin = (scalar @mpart < 2) ? 2 : $mpart[-2];
      foreach my $d (divisors($spval)) {
        next unless $d >= $dmin;
        my $q = $spval/$d;
        last if $d > $q;  # Divisors are sorted
        push @result, [ @mpart[0 .. $#mpart-1], $d, $q ];
      }
    }
    ($min, $max) = ($max+1, $#result);
  }
 return \@result;
}
</code>
The MAIN section is identical other than using "print fcnt($p,$p);" in the factorial case.


How to get model fit from GAM with ordered categorical data?

Question: I am using a GAM with ordered categorial data to estimate temporal trends in shifts from one category to another. I would like to add the model fit to my data, but I don't know what to do with what I get from predict.gam - how do I get from the linear predictor to something like the blue line in the left panel?
Or should I be thinking more in terms of probabilities, like shown in the right panel?
require(mgcv)
require(ggplot2)

## Simulate some ordered categorical data...
set.seed(3);n<-400
dat <- gamSim(1,n=n)
dat$f <- dat$f - mean(dat$f)
alpha <- c(-Inf,-1,0,5,Inf)
R <- length(alpha)-1
y <- dat$f
u <- runif(n)
u <- dat$f + log(u/(1-u))
for (i in 1:R) {
  y[u > alpha[i]&u <= alpha[i+1]] <- i
}
dat$y <- y

## fit ocat model to data...
b <- gam(y~s(x0),family=ocat(R=R),data=dat)

## predictions - linear predictor
dat$pred1 = predict(b,dat,type="link",se=F)
ggplot(dat) +
  geom_point(aes(x=x0, y=y)) +
  geom_line(aes(x=x0, y=pred1)) +      ## what I get
  geom_smooth(aes(x=x0, y=y))          ## what I'd expect

## predictions with mgcv - probabilities
pred2 = predict(b,dat,type="response",se=TRUE)
pred2 = data.frame(pred2$fit, x0=dat$x0)
pred2 = melt(pred2, id.vars = "x0")
ggplot(pred2) +
  geom_area(aes(x=x0, y=value, fill=variable), alpha=0.5)

Related:

Generalized Additive Model interpretation with ordered categorical family in R
How to choose theta θ thresholds for ocat family in mgcv package. (ordinal regression)
Answer: Your expectation is wrong; the smooth that is estimated in the model is not for some continuous axis you are forming based on the number line containing the integers for the categories. The linear predictor in the ocat() model is for a latent variable on the logit scale. The smooth in the linear predictor estimates how values on this latent variable vary as a smooth function of the covariate. The model also estimates thresholds for the cut points on the latent variable that predict the groups on the latent variable. By default, the first threshold is set to -1 in ocat(), which defines the threshold between categories 1 and 2. Later thresholds define the boundaries on the latent variable between the other categories, if any. if there are $c$ categories, there are $R = c - 1$ thesholds, and of those only $R-1$ of them are estimated from the data.
To visualise this on the linear predictor scale you can do this:
library("gratia")
library("ggplot2")
library("mgcv")

# Ordered categorical model ocat()
n_categories <- 4
df <- data_sim("eg1", n = 200, dist = "ordered categorical",
  n_cat = n_categories, seed = 42)

m1 <- gam(y ~ s(x0),
  family = ocat(R = n_categories), data = df, method = "REML")

# data slice over x0
ds1 <- data_slice(m1, x0 = evenly(x0, n = 100))
fv1 <- fitted_values(m1, data = ds1, scale = "link") # <- link scale

# extract the thresholds on the linear predictor from the model
thresh <- gratia::theta(m1) |>
  tibble::as_tibble() |>
  setNames(c("threshold"))

fv1 |>
  ggplot(aes(x = x0, y = fitted)) +
  geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.2) +
  geom_line() +
  geom_hline(data = thresh, aes(yintercept = threshold))

The model doesn't define 1 smooth line on the response scale, it defines $c$ of them, one per category. if you want a plot like the left-hand panel in your question, you should be plotting the predicted probabilities for each class.
Here's how I do this in {gratia} with it's fitted_values():
# data slice over x0 - repeated
ds1 <- data_slice(m1, x0 = evenly(x0, n = 100))
fv1 <- fitted_values(m1, data = ds1)

fv1 |>
  ggplot(aes(x = x0, y = fitted, group = category)) +
  geom_ribbon(aes(ymin = lower, ymax = upper, fill = category),
              alpha = 0.2) +
  geom_line(aes(colour = category))

Note I think I might be scrambling the categories as right now, this plot doesn't make sense when we look at the linear predictor plot from above.
Or for a model with multiple smooths, where we need to specify values for the other smooths that we wish to condition on when predicting:
m2 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3),
  family = ocat(R = n_categories), data = df, method = "REML")

# data slice over x2(!) holding other covariates at median values
ds2 <- data_slice(m2, x2 = evenly(x2, n = 100))
fv2 <- fitted_values(m2, data = ds2)

fv2 |>
  ggplot(aes(x = x2, y = fitted, group = category)) +
  geom_ribbon(aes(ymin = lower, ymax = upper, fill = category),
              alpha = 0.2) +
  geom_line(aes(colour = category))


Fancybox 2 - SyntaxError: missing : after property id

Question: I'm trying to make a custom dialog box using the fancybox plugin v2
Unfortunately, when I try to manage the display of the button with the fancybox tpl parameter I get this error:
SyntaxError: missing : after property id --> if(cbtn == 'default')
var modalMessage = function (dialmsg, action, cbtn)
{
    // Set defaults if not defined
    if (typeof dialmsg === 'undefined' || dialmsg === null)
    {
        dialmsg = 'Default message';
    }
    if (typeof action === 'undefined' || action === null)
    {
        action = 'default';
    }
    if (typeof cbtn === 'undefined' || cbtn === null)
    {
        cbtn = 'default';
    }
    // Create fancybox dialog
    $.fancybox({
        'minHeight'         : 40,
        'autoScale'         : true,
        'autoSize'          : true,
        'autoHeight'        : true,
        'autoWidth'         : true,
        'fitToView'         : true,
        'closeBtn'          : false,
        'modal'             : true,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'inline',
        'href'              : '#modal-msg',
        'padding'           : 10,
        tpl:
        {
            if(cbtn == 'default')
            {
                closeBtn: '
Close
';
            }
        },
        beforeShow: function()
        {
            $('#modal-msg').html(dialmsg);
        },
        afterClose : function()
        {
            if(action == 'reload')
            {
                parent.location.reload(true);
            }
        }
    });
}

$('#dialog').on('click', function ()
{
    modalMessage('This is a test message', 'reload');
});

HTML

Click me

I tried in this way
 tpl: function()
        {
            if(cbtn == 'default')
            {
                closeBtn: '
Close
';
            }
        }

The error disappears but it does not appear the dialog box but only the background overlay.
How could I do this? Thanks
Answer: For your situation you can use a self execution function which returns the tpl object:
...
tpl: (function() {
    var tpls = {};

    if(cbtn == 'default') {
        tpls.closeBtn = '
Close
';
    }

    return tpls;
} ())
...


If $(X,\leq)$ is a set with a total order, how can I show that there is $Y\supset X$ s.t. $Y$ has the supremum property?

Question: In my course, they defined $\mathbb R$ as the smallest set that contain $\mathbb Q$ and that has the supremum property, i.e. that all upper-bounded set has a supremum.
1) My problem, it's that I don't know how I can be sure that such a set indeed exist. I'm not so sure how to construct it.
2) Also, if I can build such a set, how can I define $x\leq y$ if $x,y\notin \mathbb Q$.

I know that this question is not as general than my title. But at the end, I wonder how to do in the very general case.
Comment: This is called the *Dedekind completion* of a linear order. Essentially, you look at bounded sets without a supremum, and you artificially add that supremum if it does not exist.
Comment: Well, if some elements of $B$ are larger than *all* elements of $A$, then they are at least as big as $\sup A$ and at least as small as $\sup B$. Or vice versa. Or, the two sets are "intertwined" and therefore would have the same new supremum.
Comment: There is only one such linearly ordered set in which $\Bbb Q$ *is dense*. That is to say, if you have two Dedekind-complete partial orders, and each of them has a copy of $\Bbb Q$ which is dense (that is, every point is the supremum of a set of rational numbers (from the relevant copy)), then the two linear orders are isomorphic. Of course we can have *larger* linear orders, they will simply have points which are not supremum of any set of rationals, though.
Comment: The argument is the same, the idea is the same. The fact I mentioned the rationals is irrelevant. This is why we call it *the* Dedekind-completion.
Comment: @AsafKaragila: Thanks a lot. And does this completion will automatically gives comparable numbers ? if $A$ and $B$ are bounded without supremum, what would assure that $\sup(A)$ and $\sup(B)$ are comparable ?
Comment: @AsafKaragila: Thank you. Very last question, after reading dedekind completion on wikipedia, I have the impression that at the end, there is only one set $E\supset \mathbb Q$ s.t. $E$ has the supremum property. Whereas my lecture said that $\mathbb R$ is defined to be the smallest one. So, I was wondering, are they sets $E$ with the supremum property such that $\mathbb R\subsetneq E$ ?
Comment: If we avoid $\mathbb Q$, but consider $(X,\leq )$ a set with a total order without the property of supremum. Is there only one $Y$ s.t. $Y\supset X$ with the supremum property, or we can have several ? Like $Z$ with supremum property s.t. $X\subset Y\subsetneq Z$.
Answer: You are right, one has to construct this set. Call a pair $(L, R)$ of proper subsets of $\mathbb{Q}$ a Dedekind cut if :

$L \cup R = \mathbb{Q}$
$\forall x \in L, \ \forall y \in R, \ x < y$

One can then define $\mathbb{R}$ as the union of $\mathbb{Q}$ with the set $D$ of all Dedekind cuts. One can then define the order $<'$ on $\mathbb{R}$ as follows :

for $q, l \in \mathbb{Q}$, $q <' l :\Longleftrightarrow q < l$
for $c = (L, R) \in D$, $q \in \mathbb{Q}$,
$c <' q :\Longleftrightarrow \forall x \in L, \ x < q$ and
$q <' c :\Longleftrightarrow \forall x \in R, \ q < x$
for $c = (L,R) \in D$ and $d = (L', R') \in D$,
$c < d :\Longleftrightarrow \exists x \in L', \ \forall y \in L, \ y < x$


Wave equation general solution

Question: Solve : $$u_{xx}+u_{xt}-20u_{tt} = 0 ,~~~~~ u(x,0) = \phi(x), u_t(x,0) = \psi(x)$$
Well, I looked through the answer and am stuck at one very important part:
The answer assumed i know how to derive the general solution for this type of question: First, i factorize and get
$$\left(\dfrac{\partial}{\partial x}+5\dfrac{\partial}{\partial t}\right)\left(\dfrac{\partial}{\partial x}-4\dfrac{\partial}{\partial t}\right)u = 0$$
And I am confused on how to derive that the general solution which is the following : $$u(x,t) = f(x+\frac{1}{4}t)+g(x-\frac{1}{5}t)$$
I looked through the proof of general solution of the wave equation and was unable to mimic it. Please help.
Comment: what was the general solution?
Comment: Sorry i will correct the grammar mistake, the general solution is the one I wrote above
Comment: Now substitute $f(ax+bt)$ in the PDE and proceed. This is D'Alembert method........
Answer: Assume that $$w=(\partial_x -4\partial_t)u.$$
Then solve
$$\left[\partial_x+5\partial_t\right]w=0$$
by the method of characteristics.
Then solve
$$w=\left[\partial_x -4\partial_t\right]u,$$
in which $w$ is now a known function.

Wave equation general solution


determine if sample size is sufficient by comparing 25% and median values

Question: Currently I have data (true population size is unknown).
There are n data points in descending order, and we know the values of 25% and 50% percentile, say x1 and x2. How can I estimate if the sample size is sufficient such that x1, x2 are within 5% of margin of errors of x1 and x2?
For example, suppose n=1000 and data={4500, 621, 500,....0.001}, and the 250-th, 500-th observations are x1=200 and x2=50. How can I know if n=1000 is big enough such that even if increasing n, x1=200 +/- 10 and x2=50 +/- 2.5?
Comment: @Glen_b Thanks. I re-edit the question and wish now it is more clear.
Answer: It is possible to put a confidence interval around an entire empirical CDF using the Dvoretzky-Kiefer-Wolfowitz inequality.
For a sample of size $n$ the empirical CDF will be within $\varepsilon$ of the true CDF with a confidence level of $1- \alpha, $ where
$$\varepsilon =\sqrt{\left( \frac{1}{2n} \right) \ln \left( \frac{2}{\alpha} \right)} $$
For $n=1000$ and a confidence level of 95% ( $\alpha = 0.05$), $\varepsilon \approx 0.0429$
Using this you can draw the confidence bounds on your empirical CDF and put confidence intervals on your estimated percentiles.
Comment: This is a good answer, and very helpful. However, I see a potential problem. If we are plotting $\hat F$, these bounds are "vertical". The confidence bounds on the quantiles however would go "horizontally". But the DKW inequality doesn't depend on $x$, hence for percentiles close to 1 (say $p=.99$) we can never get an upper bound on the quantile using this approach. Am I making any sense? Do you have any ideas on how to handle this?
Comment: There are at least two other approaches. There is a binomial-based distribution-free interval. It uses order statistics. Or you could use a resampling approach. Both of these should avoid the bounding problem you mention for extreme percentile estimation.


What are the actual RGB values of the ConsoleColors?

Question: I'm converting colored console output to HTML. Currently, I'm first translating ConsoleColors to the Color of the same name (and dark yellow manually as it is not present there).
However, I found that some Color and ConsoleColor of the same name look quite differently, for instance CC-Green is only #008000 instead of #00FF00 (which I confirmed is the actual RGB value).
I could not find a list of the actual RGB values of all ConsoleColors, which I could use in a mapping table. Does such a list exist?
Answer: I ended up just checking all values myself. The values are very different, I have no idea why people recommend converting 'by name'.
<code>Name         Actual      Drawing.Color of same name
Black        #000000     #000000
DarkBlue     #000080     #00008B
DarkGreen    #008000     #006400
DarkCyan     #008080     #008B8B
DarkRed      #800000     #8B0000
DarkMagenta  #800080     #8B008B
DarkYellow   #808000     #000000
Gray         #C0C0C0     #808080
DarkGray     #808080     #A9A9A9
Blue         #0000FF     #0000FF
Green        #00FF00     #008000
Cyan         #00FFFF     #00FFFF
Red          #FF0000     #FF0000
Magenta      #FF00FF     #FF00FF
Yellow       #FFFF00     #FFFF00
White        #FFFFFF     #FFFFFF
</code>


Make a for loop wait till a method returns true

Question: I want to make a for loop wait till a method returns true.
For Eg-
<code>   for(int i = 0; i < 100; i++)
   {
         // for loop should get executed once

          my_method(i); //this method is called

         // now for loop should wait till the above method returns true

         // once the method returns true the for loop should continue if the condition is true

   }

   public boolean my_method(int number)
   {
      // my code
      return true;
   }
</code>
I don't know how long will my_method() take to return true.
All the above codes are inside a AsyncTask.
I am new to Android Development so any help would be really Grateful.
Comment: If you are using `AsyncTask`, you have to rely on operation which are done asynchronously. What you asked is for synchronous operations. You can call `my_method()` before `for-loop` and if it returns `true` start your loop. Your current code call this method a hundred of times and I don't think this is what you want.
Comment: go with main thread instead AsyncTask.
Comment: Use a lock and wait on it.
Comment: @JaydeepPatel I cant use this code in main thread because I am trying to move and delete some files. So going to main thread may cause issues. The number of files may vary.
Comment: You should make clear if you want to do busy waiting (the application is blocked until your method returns) or if you want to execute the method in background and activate the calling thread when the method returns.
Comment: @Mekra I want to call the my_method() 100 times.
Comment: If you want to wait on your method in the loop, use a lock and wait on it in the loop.  Make your method signal the lock when done.
Comment: @mikep could you please provide a sample code so that I can understand it better.
Comment: @Pavneet_Singh Thanks for pointing out that typo.
Comment: @FlorianS. What I want is that the for loop and the method should run in background till the for loop condition is true.
Comment: @mikep could you please provide a sample code so that I can understand it better.
Answer: Why don't you use "iterator for loop" or "foreach loop" instead of just for loop.so every next value of loop will execute only then a previous value along with your method executed.
But for an option, you will require to add all integer's values in an array of integer because both options work with an array.
<code>//First create an array list of integer and use your same for loop to add all values in that array from 0 to 100

List<Integer> list = new ArrayList<Integer>();

for(int i = 0; i < 100; i++)
{
list.add(i);
}

//Now you should able to use whether foreach or iterator to execute method for each array (int) value one by one.

//Foreach example:

for (Integer i : list) {

my_method(i); //your method to execute

}

//Iterator example:

for (Iterator i = list.iterator(); i.hasNext();) {

my_method(i); //your method to execute

}
</code>
Answer: As requested:
<code>private final ReentrantLock lock = new ReentrantLock();
private final Condition done = lock.newCondition();
for(int i=0;i<100;i++)
{
     // for loop should get executed once
 lock.lock();
  try {
         my_method(i, lock); //this method is called
     done.await();
  } finally {
             lock.unlock();
      }

     // now for loop should wait till the above method returns true

     // once the method returns true the for loop should continue if the condition is true

}

public boolean my_method(int number, ReentrantLock lock)
{
  lock.lock();
  try {
    // my code
      done.signal();
  } finally {
      lock.unlock();
  }
return true;
}
</code>
Comment: You should probably mention that delaying some thread to wait for an asynchronous result is in 99% of the cases not how it should be done in Android.
Comment: Thanks. Will this code work if I use lock and unlock  any number of times?
Comment: @mikep Tried your answer but my_method() is executed only once.


worst case time complexity of finding the floor of a number in a BST

Question: I know that the worst case time complexity of searching a node in a BST is O(logn) if the tree is balanced. But what about searching for a floor of a number t in a BST?
because in the above scenario, we are not just searching for an exact node, but a node that is close or the same as t but not greater than t. there are many criterias involved. So would it still be O(logn) worst case? (tree is balanced)
below is my code and I'm struggling to find the worst case time complexity for this:
struct Node {
    int data;
    Node *left, *right;
};

int floor(Node* root, int key)
{
    if (!root)
        return INT_MAX;

    /* If root->data is equal to key */
    if (root->data == key)
        return root->data;

    /* If root->data is greater than the key */
    if (root->data > key)
        return floor(root->left, key);

    /* Else, the floor may lie in right subtree
      or may be equal to the root*/
    int floorValue = floor(root->right, key);
    return (floorValue <= key) ? floorValue : root->data;
}

Thanks.
Answer: The time complexity is still O(log), because there is only one path that is followed from the root to a leaf. The only change is that the value that comes out of the recursive call is potentially not retained, but instead the current node's value is used as return value (cf. the last statement in your code). But this is a constant operation that does not impact the overall complexity.


How to make user as an exposed filter option in filter criteria of a normal view?

Question: In a view, I want list of users of specific role to be exposed filter option, which will list all users of that role.
Example: What I want is in view type like order or customer of ubercart(example), I want user to be filter criteria with exposed filter option of specific role(buyer or seller). If i select one user that particular user order should be listed.
Is that possible?? If so then how?
Thanks in advance.
Answer: You may install this module Total Control module. After installing this module goto this link yourdomain.com/admin/structure/views/view/control_users/edit
This view provides the functionality you want.
To see it working you visit the page through this link yourdomain.com/admin/dashboard/users
EDIT I have export the view and pasted it below in-case you just need a reference and don't want to install that module.
<code>$view = new view();
$view->name = 'control_users';
$view->description = 'Total Control over user accounts: Contains a panel pane and a page to control user accounts.';
$view->tag = 'total_control';
$view->base_table = 'users';
$view->human_name = '';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'User Accounts';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'have total control';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Filter';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '35';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'name' => 'name',
  'mail' => 'mail',
  'rid' => 'rid',
  'status' => 'status',
  'created' => 'created',
  'login' => 'login',
  'delete_node' => 'delete_node',
  'edit_node' => 'edit_node',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'name' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'mail' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'rid' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'status' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'created' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'login' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'delete_node' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'edit_node' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Bulk operations: User */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'users';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = '';
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'action::user_block_user_action' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_delete_item' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_script_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_modify_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'show_all_tokens' => 1,
      'display_values' => array(
        '_all_' => '_all_',
      ),
    ),
  ),
  'action::views_bulk_operations_user_roles_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_argument_selector_action' => array(
    'selected' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'url' => '',
    ),
  ),
  'action::system_send_email_action' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 1,
    'override_label' => 0,
    'label' => '',
  ),
);
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
/* Field: User: E-mail */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
/* Field: User: Roles */
$handler->display->display_options['fields']['rid']['id'] = 'rid';
$handler->display->display_options['fields']['rid']['table'] = 'users_roles';
$handler->display->display_options['fields']['rid']['field'] = 'rid';
/* Field: User: Created date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'users';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = 'Created';
$handler->display->display_options['fields']['created']['date_format'] = 'custom';
$handler->display->display_options['fields']['created']['custom_date_format'] = 'm/d/Y';
/* Field: User: Last login */
$handler->display->display_options['fields']['login']['id'] = 'login';
$handler->display->display_options['fields']['login']['table'] = 'users';
$handler->display->display_options['fields']['login']['field'] = 'login';
$handler->display->display_options['fields']['login']['date_format'] = 'custom';
$handler->display->display_options['fields']['login']['custom_date_format'] = 'j/d g:ia';
/* Field: User: Edit link */
$handler->display->display_options['fields']['edit_node']['id'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['table'] = 'users';
$handler->display->display_options['fields']['edit_node']['field'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['label'] = 'Edit';
$handler->display->display_options['fields']['edit_node']['text'] = 'edit';
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: User: Name */
$handler->display->display_options['filters']['uid']['id'] = 'uid';
$handler->display->display_options['filters']['uid']['table'] = 'users';
$handler->display->display_options['filters']['uid']['field'] = 'uid';
$handler->display->display_options['filters']['uid']['operator'] = 'not in';
$handler->display->display_options['filters']['uid']['value'] = array(
  0 => 0,
);
$handler->display->display_options['filters']['uid']['expose']['label'] = 'User: Name';
$handler->display->display_options['filters']['uid']['expose']['operator'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['identifier'] = 'uid';
/* Filter criterion: User: Roles */
$handler->display->display_options['filters']['rid']['id'] = 'rid';
$handler->display->display_options['filters']['rid']['table'] = 'users_roles';
$handler->display->display_options['filters']['rid']['field'] = 'rid';
$handler->display->display_options['filters']['rid']['exposed'] = TRUE;
$handler->display->display_options['filters']['rid']['expose']['operator_id'] = 'rid_op';
$handler->display->display_options['filters']['rid']['expose']['label'] = 'Roles';
$handler->display->display_options['filters']['rid']['expose']['operator'] = 'rid_op';
$handler->display->display_options['filters']['rid']['expose']['identifier'] = 'rid';
/* Filter criterion: User: Name */
$handler->display->display_options['filters']['uid_1']['id'] = 'uid_1';
$handler->display->display_options['filters']['uid_1']['table'] = 'users';
$handler->display->display_options['filters']['uid_1']['field'] = 'uid';
$handler->display->display_options['filters']['uid_1']['value'] = '';
$handler->display->display_options['filters']['uid_1']['exposed'] = TRUE;
$handler->display->display_options['filters']['uid_1']['expose']['operator_id'] = 'uid_1_op';
$handler->display->display_options['filters']['uid_1']['expose']['label'] = 'Username';
$handler->display->display_options['filters']['uid_1']['expose']['operator'] = 'uid_1_op';
$handler->display->display_options['filters']['uid_1']['expose']['identifier'] = 'name';
/* Filter criterion: User: E-mail */
$handler->display->display_options['filters']['mail']['id'] = 'mail';
$handler->display->display_options['filters']['mail']['table'] = 'users';
$handler->display->display_options['filters']['mail']['field'] = 'mail';
$handler->display->display_options['filters']['mail']['operator'] = 'contains';
$handler->display->display_options['filters']['mail']['exposed'] = TRUE;
$handler->display->display_options['filters']['mail']['expose']['operator_id'] = 'mail_op';
$handler->display->display_options['filters']['mail']['expose']['label'] = 'E-mail';
$handler->display->display_options['filters']['mail']['expose']['operator'] = 'mail_op';
$handler->display->display_options['filters']['mail']['expose']['identifier'] = 'mail';

/* Display: User Admin */
$handler = $view->new_display('page', 'User Admin', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'admin/dashboard/users';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'User Accounts';
$handler->display->display_options['menu']['weight'] = '-14';
</code>
Comment: I dont want this. What i want is in view type like order or customer of ubercart(example), i want user to be filter criteria with exposed filter option of specific role.@fahad.


Using views_embed_views() to generate content for an email message. How can I get it to insert images and urls correctly for this purpose?

Question: I am using views_embed_views() to generate content for an email message. How can I get it to insert images and urls correctly for this purpose?
Or, asked another way, how can I put the contents of a view into an html email body?
Comment: Are you already sending HTML emails with images and links ?
or is this question two fold 1) how do I prorammatically send HTML emails and 2) how do I insert the out put of a view into an email ?
Answer: Use hook_mail and drupal_mail to send out e-mail. drupal_mail at the place you want to send to mail, eg. hook_cron. And hook_mail to set the content. Use drupal_mail to send parameters to hook_mail.
As for the images, make sure that you use absolute url's in views (setting on the image field).


With Mercurial, how to run a job for each changeset when doing an update?

Question: Question: When I update my working directory from one revision to the other, I'd like to run a script for each revision passed. How can I do this?
Important Constraints

The script is always the same
Traversal should happen iteratively (I don't want to do all this by hand for 100 revisions...)
The incoming hook is no option. It must happen not only after pushes or pulls, but for all updates, no matter how often I switch between revisions.

For illustration:
r1(*) -- r2 -- r3 -- r4(head)
Basically, I'd like to do
r1(*) --> r2 (then run script) --> r3 (then run script) --> r4 (then...
Let's say, my working directory is currently at r1, and now I want to update it to r4. Instead of doing a direct update (like with hg update), I'd like to update to r2 first and then run a script (update-my-database, for example). Afterwards I'd like to update to r3, then run the same script and so on.
Comment: Hello, did you check my answer?
Comment: Yes, I think I did. Can I do something more than I did? If so, I'd like to do so. Your answer was truly helpful.
Comment: I don't think you can do anything more than accepting the answer. I am happy it was helpful :-)
Answer: It is doable but we must be careful to select a linear piece from the revision graph.
Consider a minimal repository with two heads (same thing would be if two branches or two bookmarks):
$ hg log -G --template "{rev}\n"
o  4
|
| o  3
| |
| o  2
|/
o  1
|
o  0

Say we start from 1. We want to go along either head 4 (so the linear piece would be: 1, 4) or along head 3 (so the linear piece would be: 1, 2, 3).
So we will use a script with two parameters: the beginning and the end of the linear piece.
This is bare-bones but works:
for rev in `hg log -r "descendants(1) and ancestors(3)" --template "{rev}\n"`
do
    echo Updating to $rev:
    hg update $rev
    echo Executing our script:
    hg id --id --num
done

Here is the output:
Updating to 1:
0 files updated, 0 files merged, 2 files removed, 0 files unresolved
Executing our script:
4d5aba4313ce 1
Updating to 2:
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
Executing our script:
f0de0712ec00 2
Updating to 3:
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
Executing our script:
d052bd7c310b 3

The script works no matter what is the current revision of the working directory.
Before starting it, you have to do hg fetch to get the changes from the remote without applying them to the working directory and hg log --graph to understand the topology and so select the starting and ending points of the linear piece.
You also have to replace the hardcoded 1 and 3 with the $1 and $2 shell positional parameters and replace the hg id line with your actual script :-)
To understand how it works, we use a feature of mercurial called revsets (do hg help revsets to learn more) that allows to perform queries on the history graph (a bit like SQL :-)


Models for describing cluster change over time

Question: Suppose I have a set of observations encoded as a matrix $X$ whose entries $X_{it} \in \mathcal{C} $ correspond to cluster labels of experimental unit $i$ with repeated measures at time $t$, where $\mathcal{C}$ denotes a finite set of nominal cluster indicators. For clarity, here nominal is meant to emphasize that particular values of $x_{it}$ have no inherent value, and are only meaningful given other $x_{it}$s values.
What models are suitable for describing the change in clusters over time?
Comment: Usually, one talks about "clustering", if the measurements have certain attributes which allow to talk about some kind of distance between them. If you don't have those attributes, what is the basis of your clustering?
Comment: @frank right, I agree that's usually the case. For an illustrative example, what if I observe clustering of friends, but can't observe their individual characteristics? I know person 1,3,5 were together and 2, 4, 6 were together on day one, but know nothing else about these people. The next day, I learn person 1, 2, 3, 4, 5 are together and person 6 is alone, and again I know nothing else about these people.
Comment: OK, so you have a time-dependent set partition of your data. And you want to find a notion of similarity between your set partitions. So you can predict future partitions?
What are your constraints? E.g. is the number of subsets in each partition constant? Is there an upper limit of how different two consecutive set partitons can be?
Comment: @frank prediction would be a dream but it is not necessarily the ultimate goal. I don't have a hypothesis; I am merely interested in ways such a process might be described/modelled mathematically. As for constraints, there are none except maybe the number of subsets is variable across time but less than some constant $K$.
Comment: $K\ll N$ where $N$ is the number of experimental units.
Answer: Let's denote by $S$ the basic set which contains the elements that are grouped in clusters. So the clusters $C_i$ are subsets of $S$. Now, IIUC, we want the following properties to hold:

Any two different clusters $C_i$ and $C_j$ are disjoint ($C_i\cap C_J = \emptyset, i\ne j$).
All clusters together cover the whole set $S$ ($\bigcup_{i=1}^K C_i = S$)

In other words, the clustering is a set partition. So the goal is to better describe the space of set partitions; lets call it $\cal P$.
I think the first step would be to find a metric (or some weaker version of a metric) for $\cal P$. Once you have a metric, you can do all kinds of things, e.g. talk about groupings (that would then be "clusters of clusterings").
Since $\cal P$ is discrete and finite, we could maybe then think of this space as a graph, with the metric giving us a similarity value on each edge. We could cut all the edges below a certain similarity, so the graph would not have to be complete.
As far as the notion of a metric is concerned, the author of the question already mentioned the rand index; another possibility is e.g. based on the Fowlkes-Mallows index. You could also use mutual information.
For a similar question, see here.
Then, your time series of clusterings becomes a walk in the graph. You could define transition probabilities derived from the similarity values on the edges and could thus obtain some graph random walk. This would help do predictions.
Comment: You could think about only considering neighboring partitions, those that need only a small number of atomic changes to get converted into each other. Or you find a metric with easy to compute upper bound and then only compute the proper metric with those that have an upper bound above a certain threshold. The problem of high complexity is however probably baked-in when considering the space of clusterings...
Comment: I searched "distance between set partitions" on google scholar, and found e.g. this one: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.324.259&rep=rep1&type=pdf
Comment: Oo I like the idea of modelling the partitions as random walks! From a practical perspective, how should I implement this approach to compute the transition probabilities? Presumably this would involve a summation with a number of terms in the order of the size of the set of all partitions, which is intractable for any realistic sample size $N$?
Answer: To get the brainstorm-ball rolling, I'll start with a naive proposal.
A challenge in modelling cluster change over time is the inherently nominal values of cluster indicators. One way to work around this roadblock is to define random variables whose values correspond to the discrepancy between contiguous measures of partitions. In other words, define new random variables $Y_t=D(X_{\cdot t}, X_{\cdot t-1})$ for some sensible map $D$ measuring the discrepancy or similarity of two partitions. Then the problem simplifies to modelling a set of  univariate time series data. For example, $D$ could be the rand index.
More generally, the idea is to define some sensible test function that maps partitions to real numbers, e.g., one could imagine computing the discrepancy of each partition versus some constant partition instead of computing the discrepancy between contiguous partitions. For this particular example, the interpretation can become fuzzy, as the range of values is limited, i.e., $D$ is not injective. The challenge now becomes finding a sensible test function, which likely depends on the data at hand.


convert array into .txt file

Question:
Possible Duplicate:
Convert array into csv

Hi,
How to convert array into .txt file?
This is my array:
Array
(
    [OrderList_RetrieveByContactResult] => Array
        (
            [OrderDetails] => Array
                (
                    [0] => Array
                        (
                            [entityId] => 156456
                            [orderId] => 110631
                            [orderName] => testing2
                            [statusTypeId] => 15656
                            [countryCode] => AU
                            [orderType] => 2
                            [invoiceNumber] => 1001
                            [invoiceDate] => 2010-10-19T00:00:00
                            [userID_AssignedTo] => 245454
                            [shippingAmount] => 8.95
                            [shippingTaxRate] => 0
                            [shippingAttention] => tttesst
                            [shippingInstructions] => this a test
                            [shippingOptionId] => 50161
                            [discountCodeId] => 0
                            [discountRate] => 0
                            [totalOrderAmount] => 143.8
                            [directDebitTypeId] => 0
                            [directDebitDays] => 0
                            [isRecur] =>
                            [nextInvoiceDate] => 0001-01-01T00:00:00
                            [endRecurDate] => 0001-01-01T00:00:00
                            [cycleTypeID] => 1
                            [createDate] => 2010-10-19T05:40:00
                            [lastUpdateDate] => 2010-10-19T05:40:00
                            [deleted] =>
                            [products] => Array
                                (
                                    [Product] => Array
                                        (
                                            [productId] => 455
                                            [productCode] =>
                                            [productDescription] => testtest
                                            [units] => 3
                                            [unitPrice] => 44.95
                                            [unitTaxRate] => 0
                                            [totalProductPrice] => 134.85
                                            [productName] => Skin Support Tablets
                                        )
                                )

                            [addresses] => Array
                                (
                                    [Address] => Array
                                        (
                                            [addressTypeID] => 8
                                            [addressLine1] => Cebu
                                            [city] => City
                                            [zipcode] => 6000
                                            [state] => cebu
                                            [countryCode] => PH
                                        )
                                )

                        )

                    [1] => Array
                        (
                            [entityId] => 315456
                            [orderId] => 321321
                            [orderName] => testing
                            [statusTypeId] => 3213
                            [countryCode] => AU
                            [orderType] => 2
                            [invoiceNumber] => 1002
                            [invoiceDate] => 2010-10-19T00:00:00
                            [userID_AssignedTo] => 11711
                            [shippingAmount] => 8.95
                            [shippingTaxRate] => 0
                            [shippingAttention] =>
                            [shippingInstructions] =>
                            [shippingOptionId] => 50161
                            [discountCodeId] => 0
                            [discountRate] => 0
                            [totalOrderAmount] => 408.45
                            [directDebitTypeId] => 0
                            [directDebitDays] => 0
                            [isRecur] =>
                            [nextInvoiceDate] => 0001-01-01T00:00:00
                            [endRecurDate] => 0001-01-01T00:00:00
                            [cycleTypeID] => 1
                            [createDate] => 2010-10-08T18:40:00
                            [lastUpdateDate] => 2010-10-19T18:36:00
                            [deleted] =>
                            [products] => Array
                                (
                                    [Product] => Array
                                        (
                                            [productId] => 11564
                                            [productCode] =>
                                            [productDescription] =>
                                            [units] => 10
                                            [unitPrice] => 39.95
                                            [unitTaxRate] => 0
                                            [totalProductPrice] => 399.5
                                            [productName] => Acne Clearing Gel
                                        )

                                )

                            [addresses] => Array
                                (
                                    [Address] => Array
                                        (
                                            [addressTypeID] => 8
                                            [addressLine1] => Cebu City
                                            [city] => Cebu
                                            [zipcode] => 6000
                                            [state] =>
                                            [countryCode] => PH
                                        )

                                )

                        )

                )

        )

)

Comment: `file_puts_contents('file.txt', print_r($array, true));`
Comment: @rayss: Not with a structure that complex.
Comment: Your question is meaningless. .txt files have no structure.
Comment: Isn't what you display in your question a text file?
Comment: Can you show your .txt output?
Comment: I want to output into .txt file but the format inside the file looks like a csv or excel format. is that possible?
Answer: If you want it to be parseable, you can use

var_export — Outputs or returns a parsable string representation of a variable

Example
file_put_contents('array.txt', var_export($array, TRUE));

If you want it to look like in your question, you pass TRUE as the second param to print_r:
file_put_contents('array.txt', print_r($array, TRUE));

EDIT you mentioned in the comments that you want the array to be transformed to a CSV file. This is more difficult. Your array is nested, while a CSV file is basically a single dim array, e.g.
array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn');

would be equivalent to a CSV file where the first rows is the array keys and the second row the values.
k1; k2; ...; kn
v1; v2; ...; vn

The single dims arrays are usually inside another array, so you have a collection like this:
array(
   array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn'),
   array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn')
);

Here, you'd have to get the keys first and then fetch only the values from the array for the subsequent lines, e.g.
k1; k2; ...; kn
v1; v2; ...; vn
v1; v2; ...; vn

The problem is, your array is nested even deeper. Where would you put the address array? The only feasible approach would be to go over the array and fetch only those keys and values that contain a scalar type and linearize any nested arrays, e.g.
array(
   array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => array( 'skn' => 'svn' ) ),
   array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => array( 'skn' => 'svn' ) ),
);

has to be turned into
k1; k2; ...; skn
v1; v2; ...; svn
v1; v2; ...; svn

In case this isnt clear, here is an illustration what goes where:

Luckily, this can be achieved with Iterators:
$orderDetails = $array['OrderList_RetrieveByContactResult']['OrderDetails'];
foreach( $orderDetails as $key => $details ) {

    $iterator = new RecursiveIteratorIterator(
            new RecursiveArrayIterator($details));

    if($key === 0) {
        $keys = array();
        foreach($iterator as $k => $v) {
            $keys[] = $k;
        }
        echo implode(';', $keys);
    }

    $values = array();
    foreach($iterator as $val) {
        $values[] = $val;
    }
    echo PHP_EOL, implode(';', $values);
}

The above code should output the described format. See http://www.ideone.com/I70dD for an example.
To write this to a file, you can either assemble this to a string variable and then file_put_contents it all at once or you use a filepointer and write it line by line. If you dont implode it but iterate over the $flattened array, you can also use fputcsv.
Comment: @rayss that's because `iterator_to_array` assembles the array it returns in memory first and keys from a nested level will overwrite higher level keys of the same name. I have updated the code. Now it shouldnt do that anymore. If you want more control over the Iteration, you might also want to have a look at http://stackoverflow.com/questions/2207599/multidimensional-array-iteration/2207739#2207739
Comment: thank you so much its really works. thanks for the help. I learned a lot from you :)
Comment: Surely you don't want to pass true as the second argument in var_export as this exports it to a vairable rather than outputting the contents?
Comment: @Alex I want to pass it to `file_put_contents` so it can be written to a file. For that, I have to use `TRUE`.
Comment: thank you for your post it helps me a lot but theres a little problem with your code. It appears the the [countryCode] => AU does not appear instead it will replace the [countryCode] => PH from the array of product. Heres what i get:
156456;110631;testing2;15656;PH;2;.... etc
315456;321321;testing;3213;PH;2.... etc
Answer: If you want to save a variable in a text file, you could use the serialize() / unserialize() functions for that:
$data = array(1, 2, 3, '');
$toBeSaved = serialize($data);
file_put_contents('somefile.txt', $toBeSaved);

And restore it...
$toBeRestored = file_get_contents('somefile.txt');
$data = unserialize($toBeRestored);

Answer: Maybe what you want is fputcsv ?
Comment: Not with a structure that complex.
Comment: So what structure do you want ?

convert array into .txt file


How to show the content of a group on the group page when using the Group module?

Question: Using the Group module, you can create a group, say 'group ABC', and create or update some nodes so that they belong to that group. But when you visit the "Group ABC" page, you don't see those nodes. Moreover, by browsing the nodes you don't see anything indicating those nodes belong to "Group ABC".
How to list the nodes that belong to a group on the Group page?
Note: This module is available for both Drupal 7 and Drupal 8, and this question applies to both releases.
Answer: To show the content of a group, you need to create a view. The Group module provides Views 'relationships' to any node's parent group.
With that, these are the steps required:

Create a view about content.
Add a relationship to the parent group.
Add a contextual filter on the group's id (gid).
Create a page, a block, a content pane, etc (whatever fits your needs).

Below is an export of a (simplified) view created (in Drupal 7) using the steps described above:
$view = new view();
$view->name = 'group_content';
$view->description = 'Show all nodes that belong to a specific group';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Group content';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Group content';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Content: Parent group */
$handler->display->display_options['relationships']['parent_group']['id'] = 'parent_group';
$handler->display->display_options['relationships']['parent_group']['table'] = 'node';
$handler->display->display_options['relationships']['parent_group']['field'] = 'parent_group';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Group: Group ID */
$handler->display->display_options['filters']['gid']['id'] = 'gid';
$handler->display->display_options['filters']['gid']['table'] = 'groups';
$handler->display->display_options['filters']['gid']['field'] = 'gid';
$handler->display->display_options['filters']['gid']['relationship'] = 'parent_group';
$handler->display->display_options['filters']['gid']['exposed'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['operator_id'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['label'] = 'Group ID';
$handler->display->display_options['filters']['gid']['expose']['operator'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['identifier'] = 'gid';
$handler->display->display_options['filters']['gid']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'group-content';

Answer: Maybe Kristiaan Van den Eynde's reply to the question posted in this node here https://www.drupal.org/node/2689663 will be "enlightening" enough...
or this step-by-step guide here, edited by Pierre Vriens, too: https://www.drupal.org/node/2693847
Or/and this blog post: https://www.optasy.com/blog/drupal-8-group-module-how-list-related-group-content.
Good luck!


Remove button in detailview with condition in SugarCRM

Question: My code :
$GLOBALS['listbutton'] = $this->dv->defs['templateMeta']['form']['buttons'];
    if ($this->bean->status == 'Converted') {
        unset($this->dv->defs['templateMeta']['form']['buttons'][0]);
    }
    parent::display();

    $GLOBALS['log']->debug("INFOdation log Display");
    $this->dv->defs['templateMeta']['form']['buttons'] = $GLOBALS['listbutton'];

But when status  =='New' , the edit button still hide. Could you help me. I only want edit button hide when status == 'Converted', other status it has to apperance.
Comment: Can you see edit button if you remove `unset` part?
Answer: You could hide the Button with Javascript.
in the detailviewdefs.php include your script
'includes' =>
 array (
  0 =>
  array (
    'file' => 'custom/modules/Leads/button_hide.js',
  ),
 ),

With something like:
SUGAR.util.doWhen("typeof $ != 'undefined'", function(){
    if($(#status).val() == "Converted")$('#delete_button').parent().hide();
});

(SUGAR.util.doWhen ist the SugarCrm onload if ajax ist enabled)
if the Field status is not in your view you will need to add a hidden field in detailviewdefs.php and set the value with smarty code like:
<input type="hidden" id="status" value="{$fields.status.value}">


Como criar um projeto mvc no visual studio code

Question: Estou começando aprender a desenvolver para web com c# no visual studio code.
Estou tentando criar um projeto web, o problema é que o comando que estou usando "dotnet new MVC -o NomePasta " já cria uma estrutura.

Como faço para criar um projeto vazio mvc no visual studio code?
Comment: Você quer criar um projeto MVC vazio ou uma Solution vazia sem nenhum projeto dentro?
Comment: Desculpe, estou aprendendo, tem alugam entre os dois projeto.
Comment: As vezes isso pode te ajudar! https://pt.stackoverflow.com/questions/232044/sugest%C3%B5es-de-comandos-no-vscode/265191#265191
Comment: Ps.: Quando você menciona ao Visual Studio Core, seria apenas uma confusão com o Framework DotNet Core ou estaria se referindo ao Visual Studio Code?
Comment: VSCode certo? E não Core, corrige aí seu post! :) abs.
Comment: Estou me referindo o Visual studio code, porque  estou usando o sistema operacional linux.
Comment: Vou editar minha resposta
Comment: @AntonioLima, Veja o início da minha resposta atualizada.
Comment: Obrigado Leandro Angelo, a explicação esta igual a alguns site que foi pesquisado, nas não bem resumida igual a sua, obrigado ajudou muito.
Answer: Para adicionar um projeto ASP.Net Core vazio, você deve abrir um prompt de comando, navegar até o diretório onde deseja criá-la e executar o seguinte comando:
dotnet new web

O template do MVC já inclui a estrutura inicial desse tipo de projeto, você consultar todos os templates disponíveis através do comando (referência):
dotnet new -l

Os passos seguintes são para outras versões do Visual Studio, uma vez que o Visual Code não trabalha com padrão de solutions, apenas diretórios.
Para criar uma Solution vazia via Dotnet CLI, você deve abrir um prompt de comando, navegar até o diretório onde deseja criá-la e executar o seguinte comando:
dotnet new sln

Esse comando não possui nenhum argumento e irá criar um arquivo .sln com o mesmo nome do diretório onde o foi executado.
Agora para adicionar projetos à sua solution você pode utilizar os comandos sln (referência) ou seguir pelo caminho mais prático que criá-los pelo visual studio.
O mesmo pode ser feito dentro do próprio visual studio acessando o menu:
File -> New Project -> Other Project Types

E para adicionar um projeto web vazio:


Manually invoking Ajax Commands when an ajax callback is not an #ajax form callback

Question: My original post caused some confusion, so I'm re-writing it for clarity.
In Drupal, if you have an #ajax callback in a form, you can do something like this:
function my_ajax_callback(array &$form, FormStateInterface $form_state)
{
  $response = new AjaxResponse();
  $response->addCommand(new AlertCommand(t('This is from an ajax callback'));
  return $response;
}

This in turn triggers Drupal.ajaxCommands.prototype.alert(), which is located in ajax.js.
Alternatively, I can create an ajax callback of my own, that has nothing to do with a form. example.routing.yml:
mymodule.ajax
  path: '/mymodule/ajax'
  defaults:
    _controller: 'Drupal\my_module\Controller::ajaxCallback'
  # (remainder not shown)

I can create an AjaxResponse in this callback:
class Controller extends ControllerBase
{
  public function ajaxCallback()
  {
    $response = new AjaxResponse();
    $response->addCommand(new AlertCommand(t('This is from an ajax callback'));
    return $response;
  }
}

In this case, debugging has shown me that the AjaxResponse returns my command to the browser, but Drupal.ajaxCommands.prototype.alert() is not triggered.
Further debugging has shown me that ajax commands are only triggered if the AjaxResponse comes from an #ajax callback in a form, not if it's from a non-form ajax callback.
So my question is, does anyone know how to invoke ajax commands when the commands are returned from non-form ajax callback?
Answer: Like @Gaius I don't know exactly what @Jaypan wants to achieve. This example might help to make this clearer:
        var response = JSON.parse(content);
        // Create a Drupal.Ajax object without associating an element, a
        // progress indicator or a URL.
        var ajaxObject = Drupal.ajax({
          url: '',
          base: false,
          element: false,
          progress: false
        });
        // Then, simulate an AJAX response having arrived, and let the Ajax
        // system handle it.
        ajaxObject.success(response, 'success');

Normally you set an URL in Drupal.ajax() and then use ajaxObject.execute() to run the Ajax request. This example from big_pipe.js only simulates the Ajax request and then runs the Ajax commands contained in content.
Comment: For anyone who wants to see a real example of this, you can check out the Fancy Login module, in which I implemented this technique. The functions to checkout in particular are: 1) The $.ajax trigger in /js/fancy_login.js in the function(). 2) The ajax callback in /src/Controller/FancyLoginController ajax_callback()  [which I will be renaming as ajaxCallback() in the next release of the module].
Comment: That was it! Exactly what I needed. Thank you. I also re-wrote my question to make it clearer exactly what I was asking.
Answer: It might not be related and is also a rather old post, but for anybody like myself desperately searching for some hint on the Drupal 8 ajax api:
Drupal.ajax({url: '/some/url'}).execute().done(
    function(comands, statusString, ajaxObject){
        console.log("we're done ;-)");
})

This tutorial might also be helpfull: https://www.thirdandgrove.com/rendering-view-ajax-drupal-8
Comment: Thanks a lot!! I was really desperately searching for something like that and you saved me!
Answer: If your Ajax request is triggered by a link, just add the "use-ajax" CSS class to your link. And remove all the JS manually added for sending your Ajax request. It will be automatically handled by drupal.ajax .
The problem is on the front end side. Drupal return an Ajax response, but JS doesn't know it and just do nothing with it.
Comment: After another read of your post, I'm not sure my answer is what you need... Don't hesitate to comment it.
Comment: Thanks, but it wasn't what I was looking for - I've re-written my original post for clarity.


Virtualization Hardware and Software Advice; Terminal Services; Active Directory

Question: Here's what I have in mind, understand I am ignorant:
A core OS running virtual machine software - Linux (which distro?) with VMWare?
A Terminal Services virtual machine for up to 50 thin clients - Win Server 2008 R2.  The only reason I'm stuck with Windows for TS is because I can't get most users off of MS Office (Outlook in particular).
An Active Directory virtual machine - should I stick with Win Server 2008 R2, or is there a Linux distro + LDAP combo that is compatible with 2K8R2 Terminal Services?
Store shared files on a NAS, map a drive in each Terminal Services profile.
Sync the LDAP with Google Apps.
I have about a dozen laptop users - how do I handle them regarding AD/LDAP?  Roaming profiles?  I'd love to force them to boot a tiny linux image and then remote desktop into the Terminal Server... But they are going to FREAK OUT when they can't use their computer in situations where there isn't broadband access.  I'm not sure 3G is sufficient enough for a pleasant user experience.  The last thing I want is to hear every day how slow their computer is.  But on the flip side, the security and management is unparalleled.  Am I just thinking too far ahead of the curve?
We have a PBX server - should I virtualize that?
Are Blade servers simply more space efficient, "second generation" rack servers?  They're still individual servers, correct?  Or do they function like distributing computing?  A "beowulf cluster"?
If I can talk them into SSDs, should I choose those over HDDS?  I'd get two for RAID1.  Remember the data storage will be on the NAS.  The SSDs would be for the virtualized servers server.  I guess I should opt for SLC vs. MLC?  PCI-E or SATA/SAS?
Your insight is greatly appreciated.  Thanks.
Answer: Wow - so many questions, no little clarity.

Here's what I have in mind, understand I am ignorant:

Yes

A core OS running virtual machine software - Linux (which distro?) with VMWare?

VMWare is a company not a product, which of their products are you looking to use? Why wouldn't you consider a bare-metal hypervisor such as ESXi?

A Terminal Services virtual machine for up to 50 thin clients - Win Server 2008 R2. The only reason I'm stuck with Windows for TS is because I can't get most users off of MS Office (Outlook in particular).
An Active Directory virtual machine - should I stick with Win Server 2008 R2, or is there a Linux distro + LDAP combo that is compatible with 2K8R2 Terminal Services?

I'll let someone else answer this one.

Store shared files on a NAS, map a drive in each Terminal Services profile.

Fine

Sync the LDAP with Google Apps.

Why?

I have about a dozen laptop users - how do I handle them regarding AD/LDAP? Roaming profiles?

There are lots of different ways, what areyou trying to achieve?
I'd love to force them to boot a tiny linux image and then remote desktop into the Terminal Server... But they are going to FREAK OUT when they can't use their computer in situations where there isn't broadband access. I'm not sure 3G is sufficient enough for a pleasant user experience. The last thing I want is to hear every day how slow their computer is. But on the flip side, the security and management is unparalleled. Am I just thinking too far ahead of the curve?
That's not how I'd put it, again what are you trying to achieve?

We have a PBX server - should I virtualize that?

Depends what it is

Are Blade servers simply more space efficient, "second generation" rack servers?

More space efficient yes, but they're not really a replacement for rack servers - they're different beasts - usually rack servers have more expansion capability but take up more space/power/cabling etc.

They're still individual servers, correct? Or do they function like distributing computing? A "beowulf cluster"?

Correct, individual servers - they can be used for distribruted computing but so can rack servers.

If I can talk them into SSDs, should I choose those over HDDS? I'd get two for RAID1. Remember the data storage will be on the NAS. The SSDs would be for the virtualized servers server. I guess I should opt for SLC vs. MLC? PCI-E or SATA/SAS?

Why? what are you planning on using them for? just VM boot disks? what are your space requirements, what are your read/write profiles?

Your insight is greatly appreciated. Thanks.
Comment: Checking out ESXi - probably just what I need.  Did not consider it as I did not know "standalone" VM servers existed as such.  I thought they had to run on a host OS.
Comment: Why not sync with Google Apps?  From what I understand I can simply create a new user in Active Directory and the account is pushed to Google Apps.  I assume you have to pre-purchase the licenses for the account(s) so they are available.
Comment: Laptops, I'm trying to provide access to shared company files and applications.  Some employees are random individuals around the country that do not come into the main office save a few times a year.  To fix problems or reconfigure their software they have to wait, ship their laptop, or I use remoting software.  It would be great if I could administer their desktop locally on the terminal server, and they simply remote into the terminal server.  I could install full blown Windows on their laptop, but I'd like to minimize the software configuration as close to a diskless client as possible.
Comment: Since I'm shooting for only one or two servers (primary/secondary), I suppose rack servers are the best option.  My aim is torun all the virtual servers on one physical server.  That's where the SSDs come in.  I will have at minimum two virtual servers - Active Directory and Terminal Services with up to 50 concurrent users.  We are looking into ERP solutions - that would be a third VM.  PBX/Fonality would be a fourth.  I'm simply assuming faster is best if I can find a cost appropriate ssd solution - l.o.l.
Comment: Understand your first three comments now thanks. Generally the 'break-even' point for moving to blades is 5 (as most rack servers are 2U high and most blade enclosures are 10U high) - if only want two then I'd go with rack servers. I wouldn't go the SSD route just now, you could easily kill them in a year if you don't know your disk profile. Just buy a Dell R310/HP DL380/IBM x3650 M3 and fill it with as many of the largest capacity 10krpm SAS disks you can and run them in a RAID10 configuration - that'll be plenty fast enough, not too expensive and much more resilient than SSDs.
Comment: Thanks, the server recommendations are solid.  Any thoughts on my mobile users?


Linux - bash script to remove each line before the same line from a file

Question: I have an invalid xml file (it's an output of another process), I need to validate it in linux (bash script).
In the invalid file there are empty tags - without closing tags like:
<om>
<om>
<some data>
</some data>
</om>

I tried to run the following commands:

Using xsl:

xsltproc prepare_v270.xsl test.xml  > /tmp/test.xml.bak
test.xml:413282: parser error : Excessive depth in document: 256 use XML_PARSE_HUGE option
    <om>
    ^

unable to parse test.xml
2. Using xmlstarlet
 sudo xmlstarlet ed -d '//*[not(normalize-space())]' test.xml
test.xml:413282.5: Excessive depth in document: 256 use XML_PARSE_HUGE option
    <om>
    ^

And so on
I tried to write a bash script to remove each <om> line before line with <om> word by the following script:
#!/bin/sh
sed '
/\<om\>/ {
#append the next line
        N
# look for "<om>" followed by "<om>"
        /\<om\>.*\<om\>/ {
#       print
                P
#       then delete the first line
                D
        }
}' <old.xml >new.xml

But it doesn't work.
Comment: By the [definition of XML](https://www.w3.org/TR/xml/#sec-documents) there is no such thing as "invalid XML". Either a character string is a valid XML document or it is not XML at all. Anything that can correctly processes XML will fail because the input is not XML. Or to put it another way: the examples you give show tools saying this is not XML, and have successfully shown the input is not valid.
Comment: If the error is systemic i.e. every `` needs to be followed by another `` throughout the entire document, a simple lexical replacement like `sed 's%%&&%' invalid.xml >new.xml` might work. Without more infolmation about how exactly the input is broken, there is no way really to give concrete advice.
Comment: Possible duplicate of [libxml2 XML\_PARSE\_HUGE option for xmlParseMemory](https://stackoverflow.com/q/24531634/608639). It is not clear to me how `XML_PARSE_HUGE` relates to the other part of the question about invalid XML. Perhaps you should edit your question.
Comment: Thank you for the comments. If there is no invalid xml maybe I need to write a loop in bash script or using sed to remove any  before
Comment: Instead of removing something, I'd try to add something to make it valid XML. That way you don't lose information
Comment: If that program does not produce valid XML, it's likely that it has a lot of other issues as well, like wrong escaping of special characters, wrong encoding etc.
Comment: I want to use sed command for remove each  tag before  tag without anything between them. I'm looking for this solution... Thank you very much!
Answer: I found the solution - to remove a line in file if the next line is the same.
This logic removes the open tag before the same open tag.
pre=
while IFS='' read -r line || [[ -n "$line" ]]; do
   # echo "Line read from file: $line"
   # if line does not contain line pre
   if ! { [ -n "$pre" ] && [[ "$line" == "$pre" ]] ; }; then
      # echo "   <$pre> not found!"
      echo "$line"
      pre=$line
   fi
done <old.xml >new.xml

Thanks for all!!


Como inserir um array em uma variável?

Question: Percebendo que tem muito código repetitivo resolvi automatizar criando um looping de leitura das células do meu arquivo excel.
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells
#Segunda 7h40min - 8h30min
cell = cells[3]
t1cell13 = cell.paragraphs
t1cell13 = str(t1cell13[0].text.encode("utf-8"))
t1cell13 = unicode(t1cell13, "utf-8")
print t1cell13
w_sheet.write(8,10, t1cell13, style)
a1 = t1cell13

#terça 7h40min - 8h30min
cell = cells[4]
t1cell14 = cell.paragraphs
t1cell14 = str(t1cell14[0].text.encode("utf-8"))
t1cell14 = unicode(t1cell14, "utf-8")
w_sheet.write(9,10, t1cell14), style)
a2 = t1cell14

#Quarta 7h40min - 8h30min
cell = cells[5]
t1cell15 = cell.paragraphs
t1cell15 = str(t1cell15[0].text.encode('utf-8'))
t1cell15 = unicode(t1cell15, "utf-8")
w_sheet.write(t1cell15, style)
a3 = t1cell15

#quinta 7h40min - 8h30min
cell = cells[6]
t1cell16 = cell.paragraphs
print str(t1cell16[0].text.encode('utf-8'))
w_sheet.write(11,10, str(t1cell16[0].text), style)
a4 = str(t1cell16[0].text.encode('utf-8'))

#sexta 7h40min - 8h30min
cell = cells[7]
t1cell17 = cell.paragraphs
print str(t1cell17[0].text.encode('utf-8'))
w_sheet.write(12,10, str(t1cell17[0].text), style)
a5 = str(t1cell17[0].text.encode('utf-8'))

#Sabado 7h40min - 8h30min
cell = cells[8]
t1cell18 = cell.paragraphs
a6 = str(t1cell18[0].text.encode('utf-8'))

Fazendo assim:
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells

i = 3
j = 8
k = 1

while (i < 9):
    cell = cells[(i)]
    item = cell.paragraphs
    item = str(item[0].text.encode("utf-8"))
    item = unicode(item, "utf-8")
    i = i+1

    while (j < 13):
        w_sheet.write((j),10, item, style)
        j = j+1

        while (k < 7):
            a(k) = item
            k = k+1

porem na parte final do while onde tento colocar a(k), não esta funcionando precisava que a cada lopping do ultimo while me retornasse:
a1 = item
a2 = item
.
.
.
Se tiverem outra opção de solução também pode compartilhar.
Muito obrigado.
Answer: Tem alguns probleminhas.
Por exemplo:
while (i < 9):

Estes parênteses não são necessários.
Estes também não:
cell = cells[(i)]

Não entendi o que quer dizer isso:
a(k) = item

Acho que a é algo como um dicionário, então na verdade seria assim:
a[k] = item

O código final ficou assim:
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells
a = {}

i = 3
j = 8
k = 1

while i < 9:
    cell = cells[i]
    item = cell.paragraphs
    item = str(item[0].text.encode("utf-8"))
    item = unicode(item, "utf-8")
    i += 1

    while j < 13:
        w_sheet.write(j, 10, item, style)
        j += 1

        while k < 7:
            a[k] = item
            k = k+1

Comment: Acho que com `a(k) = item` ele está a tentar criar um dicionário mesmo. Era o que ia responder como solução! +1
Comment: Obrigado pela resposta tão rápida =D
no a(k) não sei te dizer se é um dicionário.
depois vou precisar usar da seguinte forma
manhasegunda = (a1, a7, a13, a19, a25, a31)
assim tenho retorno que a variavel a1 não é definida.
Obs eu tinha tentado dessa forma tbm =D
Answer: Deu certo aqui...
mudei um pouco, de qualquer forma muito obrigado =D
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells

    a = {}

    i = 3
    j = 8
    k = 1

    while k < 7:
        cell = cells[k+2]
        item = cell.paragraphs
        item = str(item[0].text.encode("utf-8"))
        item = unicode(item, "utf-8")
        w_sheet.write(k+7, 10, item, style)
        a[k] = item
        k += 1

Colocando em um array assim:
manhasegunda = (a[1], a[2], a[3], a[4], a[5], a[6])

Como inserir um array em uma variável?


Is there any difference between "margin: 0 auto;" and "margin: auto;"

Question: When we want page's main container align center, we usually use "margin: 0 auto;", but when I use "margin:auto;", behaviour are the same in some browser I have (Google Chrome, Firefox).
Answer: Yes.
margin: 0 auto;

Sets the element's left and right margins to auto, and the top and bottom margins to 0.
margin: auto;

Sets all the margins to auto. You are probably getting the same behaviour due to your  being 100% height, hence the vertical auto margins have no effect.
Comment: The body's height (which is typically auto, not 100%) has no effect on how auto vertical margins are calculated. The spec simply defines auto vertical margins to *always* be zero on in-flow block boxes. So for in-flow block boxes, the answer to the question is not yes, but no - there is no difference between margin: 0 auto and margin: auto. The answer is only yes in one other specific case: absolutely positioned elements.


Is the EM-algorithm the same thing that variational inference in LDA?

Question: I am new in the probabilistic topic modeling, and I need to understand deeply the Latent Dirichlet Allocation (LDA) process.
I understand that what is the inference process in LDA, and there are 2 "types" of inference: probabilistic methods (like the Gibbs sampling) and deterministic ones.
In the deterministic type, some papers talk about Expectation Maximization algorithm and others talk about something called Variational Inference.
So my questions are

Are those terms or concepts same?
How EM algorithm works in LDA?
Answer: First, I notice that the answer given by AdamO discusses linear discriminant analysis. Since the question mentions topic modeling, I believe it is about latent Dirichlet allocation instead.
Now to answer the question:

EM and variational inference are not the same. In EM, you maximize the likelihood or posterior wrt. the parameters with the hidden variables marginalized. In VI, the parameters are also regarded as hidden variables, and you want to approximate the posterior of the hidden variables by a variational distribution. You may think of EM as a special case of mean-field VI where the variational distributions are assumed to be point estimations.
To apply EM to LDA: In the E-step, you fix $\theta$ (the topic distribution of the document) and $\phi$ (the word distribution under a topic) and compute the distribution $q(z)$ of $z$ (the topic assignment of each word). In the M-step, you update $\theta$ and $\phi$ to optimize the expected log likelihood, where the expectation is taken based on $q(z)$.
Comment: I would say that EM is a class of *algorithms* for optimisation, and variational inference is an approach to turning inferential problems into optimisation problems.   You could (in principle) use an EM-type algorithm  to solve an optimisation problem created by variational inference.
Comment: to my understanding, the standard implementation of LDA follows variational inference, not EM. However, the difference might come off as very subtle as the outcome of both the processes are pretty much the same.