python – How to Downsample a DataFrame from a given date on a set frequency

I have a Python dataframe (let’s call it df), which has monthly (end) data beginning from 01/01/1998. I would like to have the same dataframe df, downsampled on a quarterly basis, but starting from 31/01/1998.
Hence, after 31/01/1998, the next row should contain data as of 30/04/1998 and so on.

DataFrame.asfreq() seems to be the closest to my needs as it doesnt perform any aggregation like DataFrame.resample() but my ability to “start” from a given data seems limited.

Any insights here?

programming challenge – Sort Characters By Frequency Java

For context, I worked on the LeetCode May 2020 Challenge Week 3 Day 1. The challenge was described as this:

Given a string, sort it in decreasing order based on the frequency of
characters.

Example 1:

Input: "tree"

Output: "eert"

Explanation: 'e' appears twice while 'r' and 't' both appear once. So
'e' must appear before both 'r' and 't'. Therefore "eetr" is also a
valid answer.

Example 2:

Input: "cccaaa"

Output: "cccaaa"

Explanation: Both 'c' and 'a' appear three times, so "aaaccc" is also
a valid answer. Note that "cacaca" is incorrect, as the same
characters must be together.

Example 3:

Input: "Aabb"

Output: "bbAa"

Explanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.
Note that 'A' and 'a' are treated as two different characters.

Anyways, I looked up some popular solutions. One was to get the frequency of each character and sort, and the other was the use a heap. I liked both of these solutions, but I wanted to make one where there was no sorting.

My solution involved an idea of an ArrayList of “tiers,” where the index of the tier represents the frequency. Each tier consists of an ArrayList containing the characters which the corresponding frequency. As letters increase in frequency, the higher frequency tier they move up. I also used a HashMap to keep track of which frequency tier each character was in. Upon finishing iterating through the whole string, I simply use a StringBuilder to append the letters starting at the bottom tier, reverse the StringBuilder, then return the String. I was hoping someone could give me pointers (ha, code pun) on optimizing/modifying this approach without including any kind of sorting. Below is the functional code:

public static String frequencySort(String s) {
        if (s.length() <= 1) return s;

        ArrayList<ArrayList<Character>> tieredFreq = new ArrayList<>(); // stores characters at their proper frequency "tier"
        HashMap<Character, Integer> tierOfChars = new HashMap<>(); // maps the characters to their current frequency tier
        tieredFreq.add(null); // tier 0

        for (char c : s.toCharArray()) {
            tierOfChars.put(c, tierOfChars.getOrDefault(c, 0) + 1); // add char or increment the tier of the character
            int i = tierOfChars.get(c); // i = tier of the character
            if (tieredFreq.size() <= i) tieredFreq.add(new ArrayList<>()); // if not enough tiers, add a new tier
            if (i > 1) tieredFreq.get(i - 1).remove(new Character(c)); // if c exists in previous tier, remove it
            tieredFreq.get(i).add(c); // add to new tier
        }

        StringBuilder result = new StringBuilder();
        for (int i = 1; i < tieredFreq.size(); i++) { // iterate through tiers
            ArrayList<Character> tier = tieredFreq.get(i); // get tier
            for (Character c : tier) { // for each char in tier, append to string a number of times equal to the tier
                for (int j = 0; j < i; j++) result.append(c);
            }
        }

        result.reverse(); // reverse, since result is currently in ascending order
        return result.toString();
    }

How to display the frequency spectrum of android audio output for both channels?

I want to stream DLNA audio signal to my android device and display the audio frequency spectrum for both stereo channels.

There are some apps that accept the DLNA stream on android, no problem there.
What I couldn’t find is an app that would also have built-in visualizer with a spectrum analyzer preset.

I could use a separate spectrum analyzer app, there are many to choose from. But most of them only display the spectrum of the sound coming from the microphone, not from what is currently playing on android.

The closest alternative I have found is projectM, but just couldn’t find a preset for it that would simply display the spectrum of both channels, without any other effects.

So, if we could display something like this for currently playing audio on android, it would be perfect. This may look like a single channel audio, but the blue bars represent the left channel, red – right, and purple is the sound that is coming from both channels):

enter image description here

Reference requirement – Cyclic P & # 39; polya frequency function or cyclically reducing core of the same order?

A cyclic P & # 39; polya frequency function $ f: (0.2 pi) mapsto mathbb R $ of order $ 2r + 1 $ (CPF$ _ {2r + 1} $) Fulfills
$$ det (f (x_j-y_k)) _ {j, k = 1} ^ n ge 0 $$
to the $ n = 1,2, ldots, 2r + 1 $ and
$$ x_1 <x_2 < ldots <x_n <x_1 + 2 pi, quad y_1 <y_2 < ldots <y_n <y_1 + 2 pi. $$
It is also shown that this is equivalent to order cores that reduce cyclical variations $ 2r $. They were studied by P & # 39; olya, Schoeberg and others in the 1950s. I read a summary book about this – Karlin's Total Positivity, published in 1968.

A natural modification is the consideration of CPF$ _ {2r} $, which I see neither in the early nor in the newer literature. I wonder why they didn't even think about ordering CPF. Have there been any follow-up measures since the 1950s?

Binary tree – C word frequency counter

I am writing this program based on the algorithm of the word frequency counter program in the K&R book, page 139. I have added some of my idioms, some command line options and a dynamically assignable buffer.

Use it on stdin or supply one or more files as arguments.
The option -k only takes keywords into account (starting with _ or alphabetic character) and words consisting of symbols are ignored.
The option -w considers words as a string, separated by spaces.

Here is the code:

#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* the tree node */
struct tnode {
    char *word;            /* pointer to the text */
    unsigned long count;   /* number of occurrences */
    struct tnode *left;    /* left child */
    struct tnode *right;   /* right child */
};

static int exitval = EXIT_SUCCESS;;
static int spaceword = 0;
static int keyword = 0;
static char *buf = NULL;
static size_t bufsize = 0;

#define CHECKBUF(i)                                         
    {if (bufsize == 0 || (i) >= bufsize - 1) {              
        size_t newsize = bufsize + BUFSIZ;                  
                                                            
        if (newsize <= bufsize)    /* check for overflow */ 
            errc(EXIT_FAILURE, EOVERFLOW, "realloc");       
        bufsize = newsize;                                  
        if ((buf = realloc(buf, bufsize)) == NULL)          
            err(EXIT_FAILURE, "realloc");                   
    }}

static int getfreq(struct tnode **, FILE *);
static void putfreq(struct tnode *);
static void addtree(struct tnode **, char *);
static char *getword(FILE *);
static void usage(void);

/* word frequency count */
int
main(int argc, char *argv())
{
    struct tnode *root = NULL;
    FILE *fp;
    int c;

    while ((c = getopt(argc, argv, "kw")) != -1) {
        switch (c) {
        case 'k':
            keyword = 1;
            break;
        case 'w':
            spaceword = 1;
            break;
        default:
            usage();
            break;
        }
    }
    argc -= optind;
    argv += optind;

    if (argc == 0) {
        if (getfreq(&root, stdin) == -1)
            err(EXIT_FAILURE, "stdin");
    } else {
        while (*argv) {
            if ((fp = fopen(*argv, "r")) == NULL) {
                warn("%s", *argv);
                exitval = EXIT_FAILURE;
            } else {
                if (getfreq(&root, fp) == -1) {
                    warn("%s", *argv);
                    exitval = EXIT_FAILURE;
                }
                fclose(fp);
            }
            argv++;
        }
    }
    free(buf);
    putfreq(root);

    if (ferror(stdout))
        err(EXIT_FAILURE, "stdout");

    return exitval;
}

/* print the frequency of each word in tree */
static void
putfreq(struct tnode *tree)
{
    if (tree != NULL) {
        putfreq(tree->left);
        if (printf("%7lu %sn", tree->count, tree->word) < 0)
            err(EXIT_FAILURE, "stdout");
        free(tree->word);
        putfreq(tree->right);
        free(tree);
    }
}

/* populate tree with the frequences of words in fp; return -1 on error on fp */
static int
getfreq(struct tnode **tree, FILE *fp)
{
    char *buf;

    while ((buf = getword(fp)) != NULL)
        if (!keyword || (keyword && (*buf == '_' || isalpha(*buf))))
            addtree(tree, buf);

    if (ferror(fp))
        return -1;

    return 1;
}

/* add a node with w, at or below p */
static void
addtree(struct tnode **p, char *w)
{
    int cond;

    if (*p == NULL) {    /* if a new word has arrived, make a new node */
        *p = malloc(sizeof **p);
        if (*p == NULL)
            err(EXIT_FAILURE, "malloc");
        if (((*p)->word = strdup(w)) == NULL)
            err(EXIT_FAILURE, "strdup");
        (*p)->count = 1;
        (*p)->left = (*p)->right = NULL;
    } else if ((cond = strcmp(w, (*p)->word)) == 0) { /* repeated word */
        (*p)->count++;
    } else if (cond < 0) {              /* less than into left subtree */
        addtree(&((*p)->left), w);
    } else if (cond > 0) {          /* greater than into right subtree */
        addtree(&((*p)->right), w);
    }
}

/* get next word from fp; if fp is NULL, free buffer and return null */
static char *
getword(FILE *fp)
{
    size_t i = 0;
    int c;

    while (isspace(c = getc(fp)))
        ;

    if (c == EOF)
        return NULL;

    if (spaceword) {
        while (!isspace(c)) {
            CHECKBUF(i);
            buf(i++) = c;
            c = getc(fp);
        }
        goto done;
    }

    if (c == '_' || isalpha(c)) {
        while (c == '_' || isalnum(c)) {
            CHECKBUF(i);
            buf(i++) = c;
            c = getc(fp);
        }
        ungetc(c, fp);
        goto done;
    }

    while (c != '_' && !isalpha(c) && c != EOF && !isspace(c)) {
        CHECKBUF(i);
        buf(i++) = c;
        c = getc(fp);
    }
    ungetc(c, fp);

done:
    buf(i) = '';
    return buf;
}

/* show usage */
static void
usage(void)
{
    (void)fprintf(stderr, "usage: wfreq (-kw) (file...)n");
    exit(EXIT_FAILURE);
}

Here is an example of use wfreq(1) (the name I gave this word frequency counter) on its own source code, with the option -k::

      1 BUFSIZ
      4 CHECKBUF
      2 EOF
      1 EOVERFLOW
     10 EXIT_FAILURE
      1 EXIT_SUCCESS
      5 FILE
     12 NULL
      4 _
      3 a
      1 add
      5 addtree
      1 and
      4 argc
      8 argv
      1 arrived
      1 at
      1 below
      3 break
     14 buf
      1 buffer
      7 bufsize
     23 c
      2 case
      8 char
      1 check
      2 child
      4 cond
      5 count
      1 ctype
      1 default
      1 define
      3 done
      1 each
      5 else
      7 err
      1 errc
      1 errno
      1 error
      1 exit
      4 exitval
      1 fclose
      2 ferror
      1 file
      1 fopen
      1 for
     18 fp
      1 fprintf
      4 free
      1 frequences
      2 frequency
      1 from
      1 get
      4 getc
      4 getfreq
      1 getopt
      3 getword
      2 goto
      1 greater
      7 h
      1 has
     10 i
     23 if
      2 in
      7 include
     10 int
      2 into
      1 is
      1 isalnum
      3 isalpha
      3 isspace
      1 k
      4 keyword
      2 kw
      6 left
      1 less
      1 long
      1 lu
      1 main
      1 make
      2 malloc
      2 n
      2 new
      3 newsize
      1 next
      3 node
      1 null
      1 number
      1 occurrences
      3 of
      2 on
      2 optind
      1 or
      1 overflow
     14 p
      1 pointer
      1 populate
      1 print
      1 printf
      5 putfreq
      1 r
      3 realloc
      1 repeated
      7 return
      6 right
      4 root
      3 s
      1 show
      3 size_t
      1 sizeof
      3 spaceword
     15 static
      1 stderr
      2 stdin
      1 stdio
      1 stdlib
      3 stdout
      1 strcmp
      2 strdup
      1 string
     10 struct
      2 subtree
      1 switch
      1 text
      2 than
      4 the
     10 tnode
      1 to
     13 tree
      2 ungetc
      1 unistd
      1 unsigned
      5 usage
      9 void
      7 w
      2 warn
      1 wfreq
      7 while
      2 with
     10 word
      1 words

Frequency of sitemap change – daily versus weekly

Google Sitemaps have a Refresh Frequency parameter (Change Frequency) that tells GoogleBot how often a web page is updated. For example, a blog homepage can be updated as often as "daily", while the individual blog entry entries are updated "never". The correct setting of the update frequency of the links in a Google sitemap is of crucial importance for search engine optimization (SEO).

Make sure that you keep your update frequency for individual posts (which do not change significantly) at "Never" or at most "Year". Based on our experience, I recommend setting this to "NEVER" for large websites (blogs, forums) with hundreds of thousands of posts (pages) that change rarely or never.

Filtering – An attempt is made to filter out zero frequency components using a low pass filter

seq = Rescale[
Table[SawtoothWave[n/16.], {n, 0, 255}] + 
RandomReal[{-0.1, 0.1}, 256]];
GraphicsRow[{Periodogram[seq, PlotRange -> All], 

GraphicsRow[ListLinePlot /@ {seq, LowpassFilter[seq, .5]}] Spectrogram[seq, 128, 32]}]

My understanding is that I run seq through a low pass filter [.5]

The frequency of trading is critical

The trading frequency offers chances of winning. The more options we can find, the more profit we should expect. For example, a strategy with a very high profit factor of 4 (profit factor is total profit divided by total loss) may not generate as much profit as a more active system with a profit factor of only 2. Because the strategy with a lower profit factor is profitable and offers much more Possibilities. He can easily make more total profit than the system with the much higher profit factor.

http://www.forex-metal.com/affiliate/46199/2