Nginx Amplify "Regex location has no regex pattern". How to fix lines in Nginx?

Question: I am running Nginx with Nginx Amplify. In my Amplify>Analyzer>Static Analysis Section I am gettin the following errors:
Regex location has no regex pattern
Regex location has a valid modifier, but does not have a regex pattern.
Performance-wise it is more efficient to configure exact or prefix matching for locations that do not require regex matching. It is also less prone to errors. Please refer to the documentation describing location directive to learn more.
Check the following files:
/etc/nginx/conf.d/mail.example.com.conf, line 27
/etc/nginx/conf.d/mail.example.com.conf, line 89
/etc/nginx/sites-enabled/03-example2.com.conf, line 176
/etc/nginx/sites-enabled/03-example2.com.conf, line 265

My "mail.example.conf" virtual host looks like this:
server {
    # Restrict access to LAN & Other IP's
    allow 192.168.x.x/24; # AC3200 LAN IP Address
    allow x.x.x.x/32; # Work IP address
    allow x.x.x.x/32; # Apt. IP Address
    deny all;
    #error_page 403 =444;

    # Begin Server Directives
    server_name mail.example.com;
    root /var/www/roundcube/;
    index index.php index.html index.htm;

    # Logs
    error_log /var/log/nginx/mail.example.com.error.log;
    access_log /var/log/nginx/mail.example.com.access.log;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        include snippets/fastcgi-php.conf;
    }

    location ~ /.well-known/acme-challenge {
        allow all;
    }
    location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }
    location ~ ^/(bin|SQL)/ {
        deny all;
    }
    # A long browser cache lifetime can speed up repeat visits to your page
    location ~ \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
        access_log off;
        log_not_found off;
        expires 360d;
    }

    listen *:443 ssl;
    http2 on;
    ssl_certificate /etc/letsencrypt/live/mail.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mail.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/ssl/private/dhparams4096.pem; # Managed by admin

    add_header Strict-Transport-Security "max-age=31536000" always; # managed by Certbot

    ssl_trusted_certificate /etc/letsencrypt/live/mail.example.com/chain.pem; # managed by Certbot
    ssl_stapling on; # managed by Certbot
    ssl_stapling_verify on; # managed by Certbot

}
server {
    if ($host = mail.example.com) {
        return 301 https://$host$request_uri;
    }
    # managed by Certbot

    # Restrict access to LAN & Moms IP & Apartment IP's
    allow x.x.x.x/24; # LAN IP Address
    allow x.x.x.x/32; # Work IP address
    allow x.x.x.x/32; # Apt. IP Address
    deny all;
    #error_page 403 =444;

    # Begin Server Directives
    listen *:80;
    server_name mail.example.com;
    root /var/www/roundcube/;
    index index.php index.html index.htm;

    error_log /var/log/nginx/mail.example.com.error.log;
    access_log /var/log/nginx/mail.example.com.error.log;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        #try_files $uri =404;
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        include snippets/fastcgi-php.conf;
    }

    location ~ /.well-known/acme-challenge {
        allow all;
    }
    location = ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }
    location ~ ^/(bin|SQL)/ {
        deny all;
    }
    # LINUXBABE + Extra Extensions
    # A long browser cache lifetime can speed up repeat visits to your page
    location ~ \.(txt|flv|pdf|avi|mov|ppt|wmv|mp3|ogg|webm|aac|jpg|ogg|ogv|svgz|eot|otf|mp4|rss|atom|zip|tgz|gz|rar|bz2|doc|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|jpeg|gif|png|swf|jpeg|webp|svg|woff|woff2|ttf|css|js|ico|xml|otf|woff|woff2)$ {
        access_log off;
        log_not_found off;
        expires 1y;
    }
}

In this file it seems Amplify is talking about this line:
location ~ /.well-known/acme-challenge {

My /etc/nginx/sites-enabled/03-example2.com.conf file looks like:
server {
    listen 80;
    server_name example2.com www.example2.com;
    return 301 https://$host$request_uri;
}

server {
    listen *:443 ssl;
    http2 on;
    server_name example2.com www.example2.com;
    root /var/www/example2.com/;

    ##
    # SECURITY HEADERS
    ##

    # Strict Transport Security Response Header
    # Use "always" Paramater to help prevent MITM attacks.
    # ADMIN Note: Including the Preload Paramerter will cause web browsers to cache this header
    # permanently in their browser code for about two months. Use only if you want to permanently
    # commit this header to your site. If you change it, it will take a long time for changes to
    # be reflected in the web browsers.
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;

    # Content Security Policy (CSP)
    #add_header Content-Security-Policy "frame-ancestors 'self';";
    # https://gabriel.nu/tutorials/Ubuntu-20.04-NGINX-LEMP-secure-web-server-for-WordPress-DIY.html
    add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
    #add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'";
    # https://walterebert.com/blog/using-csp-wordpress/
    #add_header Content-Security-Policy "default-src 'self'; img-src 'self' data: http: https: *.gravatar.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' http: https: fonts.googleapis.com; font-src 'self' data: http: https: fonts.googleapis.com themes.googleusercontent.com;" always;
    # https://nowherelan.com/2018/12/27/secure-your-wordpress-site-with-the-content-security-policy-csp-http-header-in-apache/
    #add_header Content-Security-Policy "default-src 'self'; img-src 'self' data: http: https: *.gravatar.com *.wp.com *.wordpress.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' http: https: *.wp.com *.wordpress.com; style-src 'self' 'unsafe-inline' http: https: fonts.googleapis.com *.wp.com *.wordpress.com; font-src 'self' data: http: https: fonts.googleapis.com themes.googleusercontent.com *.wp.com *.wordpress.com; frame-src 'self' 'unsafe-inline' 'unsafe-eval' http: https: *.wp.com *.wordpress.com"

    # Secure MIME Types with X-Content-Type-Options. Below line adds the X-Frame-Options header in Nginx.
    add_header X-Content-Type-Options "nosniff" always;

    # Referrer Policy
    #add_header Referrer-Policy "strict-origin";
    # https://gabriel.nu/tutorials/Ubuntu-20.04-NGINX-LEMP-secure-web-server-for-WordPress-DIY.html
    add_header Referrer-Policy "no-referrer-when-downgrade" always;

    # Permissions Policy
    add_header Permissions-Policy "geolocation=(), autoplay=(), encrypted-media=(), midi=(), usb=(), sync-xhr=(), microphone=(), camera=(), magnetometer=(), gyroscope=(), fullscreen=(self), payment=(self)";

    # X-FastCGI-Cache
    # This line adds the X-FastCGI-Cache header in the HTTP response. It can be used to validate whether
    # the request has been served from the FastCGI cache or not.
    # ADMIN Note: Linuxbabe originally had this directive in "location ~ \.php$ {", however, we don't use it
    # there because it invalidates any other currently used headers and only implements itself.
    add_header X-FastCGI-Cache $upstream_cache_status always;

    # Clear Site Data
    # When we use a webpage, we can leave various pieces of data in the browser that we'd like to clear
    # out if the user logs out or deletes their account. Clear Site Data gives us a reliable way to do
    # that.
    # ADMIN Note: We decided to enable it globally on all pages via:
    add_header Clear-Site-Data "*";

    # X-Frame Options
    # Prevent click jacking by adding an X-Frame-Options header
    add_header x-frame-options "SAMEORIGIN" always;

    # X-SSS Protections
    # Enable X-XSS-Protection header in Nginx
    add_header X-XSS-Protection "1; mode=block" always;

    # LINUXBABE
    # If you allow people to upload files, or are concerned about intruders using a different flaw to get
    # files onto your server AND the content on your domain should not be accessed via other websites
    # possibly trying to impersonate you, then yes X-Permitted-Cross-Domain-Policies "none" will provide a
    # security benefit. The attack is less relevant these days, as any user of modern software first
    # needs to be tricked into allowing Flash or active PDF content.
    # If your website is just a regular website with nothing that requires a login to access, then you don't need it.
    # https://www.linuxbabe.com/ubuntu/install-wordpress-ubuntu-20-04-nginx-mariadb-php7-4-lemp
    # https://security.stackexchange.com/questions/166024/does-the-x-permitted-cross-domain-policies-header-have-any-benefit-for-my-websit
    add_header X-Permitted-Cross-Domain-Policies none;

    # LINUXBABE (User recommendation)
    # Ignore Cache Control
    # Keep fastcgi working if it's not getting hits
    # ADMIN Note: Only use this if fastcgi cache status is not getting hits
    #fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

    ##
    # SSL
    ##

    # Certificate Path (signed)
    ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; # Managed by ADMIN
    # Certificate Path (intermediate)
    ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem; # Managed by ADMIN
    # Certificate Path (Chain of trust of OCSP response using Root CA and intermediate certificates)
    ssl_trusted_certificate /etc/letsencrypt/live/example2.com/chain.pem; # Managed by ADMIN
    # Perfect Forward Secrecy (Diffie Hellman 4096) Path
    ssl_dhparam /etc/ssl/private/dhparams4096.pem; # Managed by ADMIN

    # Mozilla Modern Compatibilty
    # Strict Settings with OCSP stapling turned on for A+ Rating at ssllabs.com
    ssl_protocols TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLERequires nginx >= 1.13.0 else use TLSv1.2 # Dropping TLSv1.1 for modern compatability.
    ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
    ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
    ssl_prefer_server_ciphers on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m; # About 40000 sessions
    ssl_session_tickets off;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 22.214.171.124 18.104.22.168;

    ##
    # LOGS
    ##

    # ADMIN Note: Adding "if=$log_ip" to the end of access log lines will exclude your own ip address from access logs to prevent skewing data

    # Access Log (Netdata)
    access_log /var/log/nginx/example2.com.access.log netdata if=$log_ip;
    # Access Log (Amplify)
    access_log /var/log/nginx/example2.com.access.log apm if=$log_ip;
    # Error Log
    error_log /var/log/nginx/example2.com.error.log warn;

    ##
    # PAGESPEED
    ##

    # ADMIN Note: Pagespeed is broken on Nginx v1.25.1 and up, so we should comment all of it out here and in the "nginx.conf" file

    # Settings per this virtual host
    # Enable Pagespeed module
    #pagespeed on;
    #pagespeed Domain http*://*.example2.com;

    # Settings per all virtual hosts
    #include /etc/nginx/pagespeed.conf;

    ##
    # LOCATION DIRECTIVES 1
    ##

    index index.php index.html index.htm index.nginx-debian.html;

    # ADMIN
    # https://serverfault.com/questions/1137324/difference-between-3-similar-nginx-location-directives-provided-in-three-separat/1137342#1137342
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    ### BEGIN: "Converter for Media" Wordpress Plugin
    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
        set $ext_avif "";
    }

    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
        set $ext_webp "";
    }

    location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
        add_header Vary Accept;
        expires 365d;
        try_files
            /wp-content/uploads-webpc/$path.$ext$ext_avif
            /wp-content/uploads-webpc/$path.$ext$ext_webp
            $uri =404;
    }
    ### END: "Converter for Media" Wordpress Plugin

    # ADMIN
    # https://serverfault.com/questions/755662/nginx-disable-htaccess-and-hidden-files-but-allow-well-known-directory
    # location ~ /.well-known {
    location ~ /\.well-known {
        allow all;
    }

    # ADMIN
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # ADMIN
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # LINUXBABE
    location ~ ^/wp-json/ {
        rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
    }

    # LINUXBABE
    location ~ /wp-sitemap.*\.xml {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # LINUXBABE
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    # LINUXBABE
    location = /50x.html {
        root /var/www/html;
    }

    # ADMIN
    # DISALLOW ACCESS of /xmlrpc.php
    # EXCEPT FROM internal IP's and Home & Apartment IP's.
    #location ^~ /xmlrpc.php$ {
        #allow xxx.xxx.xx.x/24; # AC3200 LAN IP Address
        #allow xxx.xx.xxx.xxx/32; # Home IP address
        #allow xxx.xx.xxx.xxx/32; # Apt. IP Address
        #deny all;
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        #include snippets/fastcgi-php.conf;
    #}

    # ADMIN
    # DISALLOW ACCESS of /admin
    # EXCEPT FROM internal IP's and Home & Apartment IP's
    location ^~ /admin/ {
        #satify all;
        allow xxx.xxx.xx.x/24; # AC3200 LAN IP Address
        allow xxx.xx.xxx.xxx/32; # Home IP address
        allow xxx.xx.xxx.xxx/32; # Apt. IP Address
        deny all;
        # Require basic auth login for allowed IP's
        auth_basic "You Don't belong here. Get out!";
        auth_basic_user_file /etc/nginx/basic_auth/auth.admin;
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        include snippets/fastcgi-php.conf;
    }

    # ADMIN
    # DISALLOW ACCESS of /wp-login.php
    # EXCEPT FROM internal IP's and Home & Apartment IP's.
    #location ^~ /wp-login.php {
        #allow xxx.xxx.xx.x/24; # AC3200 LAN IP Address
        #allow xxx.xx.xxx.xxx; # Home IP address
        #allow xxx.xx.xxx.xxx; # Apt. IP Address
        #deny all;
        # Require basic auth login for allowed IP's
        #auth_basic "You Don't belong here. Get out!";
        #auth_basic_user_file /etc/nginx/basic_auth/auth.wp-login;
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        #include snippets/fastcgi-php.conf;
    #}

    # ADMIN
    # DISALLOW ACCESS of PHP In Upload Folder
    location /wp-content/uploads/ {
        location ~ \.php$ {
            deny all;
        }
    }

    # ADMIN
    # DISALLOW ACCESS of hidden files
    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

    ##
    # BEGIN: CACHE / SKIP CACHE
    ##

    # LINUXBABE
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    # Don't Skip Cache by Default
    set $skip_cache 0;

    # LINUXBABE
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    # POST requests should always go to PHP
    if ($request_method = POST) {
        set $skip_cache 1;
    }

    # LINUXBABE
    # URLs containing query strings should always go to PHP
    # ADMIN Note: You might want to be sure to turn off query strings in H-code wordpress theme, and other themes
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    if ($query_string != "") {
        set $skip_cache 1;
    }

    # LINUXBABE
    # Don't cache uris containing the following segments
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    # https://easyengine.io/wordpress-nginx/tutorials/plugins/woocommerce/
    # https://docs.cleavr.io/guides/woocommerce/
    if ($request_uri ~* "/wp-admin/|/wp-json/|/login/|/register/|/shopping-cart.*|.*add-to-cart.*|.*empty-cart.*|/cart.*|/checkout.*|/addons.*|/my-account.*|/wishlist.*|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") {
        set $skip_cache 1;
    }

    # LINUXBABE
    # Don't use the cache for logged in users or recent commenters
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $skip_cache 1;
    }

    # LINUXBABE
    # Cache Bypass for specified IP's
    # Test the upstream (PHP-FPM and MariaDB) response time. By adding the following
    # lines we tell Nginx to bypass the FastCGI cache for our own public and local IP addresses.
    # Skip the fastCGI Cache for "Apartment Public IP|Work Public IP|Apartment LAN Subdomain".
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    #if ($remote_addr ~* "xxx.xx.xxx.xxx|220.127.116.11|xxx.xx.xxx.xxx|192.168.25..*") {
    #    set $skip_cache 1;
    #}

    ##
    # END: CACHE / SKIP CACHE
    ##

    # LINUXBABE
    # Google Sitemaps / Yoast SEO Rules:
    # If you use the Yoast SEO or Google XML Sitemap plugins to generate sitemap, then
    # you need to move the Yoast/Google XML rewrite rules here, below the skip cache rules (below this line).
    # https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
    # Rules:

    ##
    # LOCATION DIRECTIVES 2
    ##

    # LINUXBABE
    # Pass Fastcgi to PHP
    location ~ \.php$ {
        # Pass FastCGI to PHP7.4 with included settings in the snippet
        include snippets/fastcgi-php.conf;
        # FastCGI Cache
        #fastcgi_cache off;
        fastcgi_cache example2.com;
        fastcgi_cache_valid 200 301 302 12h;
        fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
        fastcgi_cache_min_uses 1;
        fastcgi_cache_lock on;
        # Tell Nginx to send requests to upstream PHP-FPM server, instead of trying to find files in the
        # cache. If the value of $skip_cache is 1, then the first directive tells Nginx to send request
        # to upstream PHP-FPM server, instead of trying to find files in the cache.
        # ADMIN Note: fastcgi_cache_bypass $skip_cache and fastcgi_no_cache $skip_cache should be
        # uncommented if using google XML sitemap plugin, or Yoast SEO Plugin, or if you want to
        # enable the skip cache rules above.
        fastcgi_cache_bypass $skip_cache;
        # This directive tells Nginx not to cache the response.
        fastcgi_no_cache $skip_cache;
    }

    ##
    # NGINX CACHE PURGING in WORDPRESS with Nginx_Cache_Purge MODULE
    ##

    # Cache Purge
    # This enables the ngx_http_cache_purge_module.so module to work with Nginx Helper in Wordpress.
    # Cache Purging should be restricted to allowed IP addresses.
    # If not set, an attacker may be able to wipe your nginx fastcgi cache using simple GET requests. # (Linuxbabe User Comment).
    # This location block enables cache purge but restricts it to your ip address and to your loopback address.
    # Note: This is broken and we haven't tried to fix it. So, we are using wordpress Nginx Helper cache purge instead. Comment this out.
    #location ~ /purge(/.*) {
        #allow 127.0.0.1; # Server Loopback Address
        #allow xxx.xx.xx.x; # Server IPv4 address
        #deny all;
        # Enable http-cache-purge module in nginx for above IP addresses
        #fastcgi_cache_purge example2.com "$scheme$request_method$host$1";
    #}

    # LINUXBABE (+ ADMIN Extra Extensions)
    # Speed up repeat visits to your page with a long browser cache lifetime
    location ~ \.(txt|flv|pdf|avi|mov|ppt|wmv|mp3|ogg|webm|aac|jpg|ogg|ogv|svgz|eot|otf|mp4|rss|atom|zip|tgz|gz|rar|bz2|doc|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|jpeg|gif|png|swf|jpeg|webp|svg|woff|woff2|ttf|css|js|ico|xml|otf|woff|woff2)$ {
        access_log off;
        log_not_found off;
        expires 1y;
    }
}

In this file it seems Amplify is talking about these lines:
location ~ /\.well-known {

and
location ~ /\. {

In both files, what should I find and replace in the corresponding lines to satisfy Amplify's suggestions?
Answer: These are not errors - they are warnings. Nginx and ACME will still work. To make your site go a little faster, burn a little less CPU and get rid of the warnings, just change the regex to a literal prefix:
change:
location ~ /.well-known/acme-challenge { (which is *very badly written regex) to location /.well-known/acme-challenge { (i.e. remove ~ and any regex escaping) etc.
Comment: Then read about them. Start from https://nginx.org/en/docs/http/ngx_http_core_module.html#location
Comment: Thankyou! But what about "location ~ /\.well-known {" and "location ~ /\. {" in "03-example2.com.conf" ?
Comment: Remove the regex operator and any escaping (the `\\`)
Comment: great. But I don't know what a regex operator is and what an escape for the "\" character is either.
Comment: @EsaJokinen I read this multiple times, and am still having problems comprehending it. It's very complicated, and I have only limited relative examples to help me understand. Do you think you could just post the answer to what "location ~ /\.well-known {" and "location ~ /|. {" should look like when properly set?
Comment: The operators are called *modifier*s  in the documentation for the `location` directive. The modifiers `~`, `~*` & `^~` are related to regular expressions, whereas `=` is for exact matches. No operator means it is just a simple prefix string. And if you read any article on *regular expressions* you would find out that `\` is used for escaping metacharacters when you want to use the literal character in your regular expression.
Comment: Your question is essentially a request: "I got this error and this is my configuration, please fix it for me." This is not a configuration writing service. This is a community for professionals we expect to be able to read documentation and show at least some research effort before asking.


Determine the most important documents for supervised learning

Question: I have somewhat of a general/high level question.
Assume I'm doing supervised machine learning on some text data (tweets for example) and categorizing the documents to a certain taxonomy (multi-class classification). My supervised model performs fairly well on testing data but what I'm trying to do now is find a way to sort out which documents from the production data (not human labeled) if added to the training set would improve accuracy the most on that particular production data set.
The idea is once the initial predictions are made on production data, another algorithm would be run to determine the n most important documents (say 500) that if manually labeled by a human and added to the training set would improve accuracy the most, assuming the model does a 2nd round of prediction after the n documents have been added to the training set.
So the process would look like this:

Initial predictions on production data are made
Algorithm runs to determine the most important records to increase accuracy of the model (based on features most likely).
Human reviews these most important records and adds them to the training set
A 2nd round of prediction takes place, hopefully with a better accuracy metric

I'm thinking of using something like K-Means after doing some dimensionality reduction since it's NLP problem with lots of features.
Does anyone have any experience or suggestions in regard to this topic? Am I on the right track?
Answer: Perhaps you might find it useful to take cues from query strategy frameworks in active learning, which evaluate the informativeness of unlabeled instances (so as to pick instances to be labeled). A good starting resource could be Section 3 of Active Learning Literature Survey (2010).
For example, the uncertainty sampling strategy means picking the labels for which your model's predictions have the highest uncertainty for---if your model has some sort of entropy measure.
As for what the process might look like, a possible alternative to selecting these ~500 important records at once might be to iteratively select, possibly in batches, query instances to be labeled by an oracle. This would allow later query instance choices to be better-informed.


Can you send a Start, Stop and Set Time MIDI messages to GarageBand?

Question: While standard Start/Stop/"Set Time" MIDI messages work with Logic Pro, sending them to GarageBand doesn't do anything (I only see GarageBand getting MIDI messages, but it doesn't do anything with them).
Is it possible to have GarageBand start, stop and set the time through MIDI? What would be the codes?
I tried to find MIDI codes on the web, but playing with them didn't work (I lost the URLs, now). I also tried GarageRemote, which somehow converts MIDI messages to GarageBand messages, but I didn't succeed either.
PS: for reference, for Logic Pro, the following MIDI sequences do work (after "F0 7F 7F 06", and before a closing "F7"):

Start: 02
Stop: 01
Set time: 44 06 01 hour minutes seconds frac_seconds 0

PPS: someone else had the same question on Reddit… and got no answer. But that was three years ago.
Answer: Not a complete answer, but it might help you a bit further? It seems you can send start and stop midi signals from a controller to Garageband, e.g. here in the Nektar GX 61 manual p.12 (http://support.nektartech.com/Downloads/Impact_Guides/Nektar_DAW_Integration_for_Impact_GX49_and_61_English.pdf) it shows how you can use the transport buttons on the keyboard to control GB.
So, yeah, start and stop I think should be possible.
Comment: Indeed, thanks. There is hope. Now, for all practical purposes, I would need to get the MIDI sequences, but knowing that they exist helps targeting searches.
Comment: @EricOLebigot Somebody seems to have figured it out: https://www.muratnkonar.com/otherstuff/garageremote/ Maybe you can send them a mail?
Comment: Yeah, that's the app I had tried, and it didn't work. Good idea, about sending an email. Will do.


How to read movable scale chart for A minor pentatonic?

Question: I bought a guitar chart and it has this figure for moveable minor pentatonic scale:

I know the number 1 box pattern of the minor pentatonic scale (Justin guitar course). I play it starting on the 5th fret to get an A minor pentatonic scale.
When trying to understand how to read the scale diagram, I came across this - The Minor Pentatonic Scale | Guitar Lesson with Diagrams. Based on the different patterns shown there, I added those boxes and numbered them.
I have 3 questions:

Without referring to a different source, how will I know from the scale diagram, which frets will be part of a pattern? For example, in 1 we have frets 1,2,3,4.
It says all scale diagrams are moveable, does this mean that pattern 1 for example when moved to fret 6 will give the A# minor pentatonic?
What is the benefit of using one pattern over the other?

Reference diagram used to make the boxes in the first diagram:
Answer: You are correct to play the first shape on 5th fret for A Minor Pentatonic
Your questions:
You will not know the frets until you know what key you are playing in. For the minor pentatonic, the first finger of shape 1 will be the root of the scale.  So whatever fret you choose starting with first finger will be the key. For example,  8th fret - C pentatonic Minor.
Yes you're correct, the 6th fret first pattern would be A# (or Bb depending on how you are thinking about the key)
Using different patterns will give you options on how to play phrases you would commonly hear in guitar solos.  Pattern one on the chart is the most popular and best place to start. Stairway to Heaven guitar solo demonstrates the multiple patterns as Jimmy Page moves up the neck. He also adds other notes such as the F note in the Pentatonic scale during the first phrase of solo.
See tabs for guitar solos for blues and rock to get an idea of how players use the patterns.  Jimmy Page, Eric Clapton, BB King, Stevie Ray Vaughn are good players to start with in my opinion.
Comment: "[Jimmy Page] also adds other notes..." Great point, I think this is important for OP, and everyone really.  I often see questions like "Why did XYZ add a note that's not in the scale they're playing", "why did XYZ use this chord when it's not technically in the key?" -- because it sounds good/adds flair/etc. You are the music maker, and the theory is primarily there as a guide, but you're certainly not beholden to following the theory 100% all the time.
Answer: Each one of the circles indicates a note belonging to the minor pentatonic scale. Those notes are also the same ones that belong to the major pentatonic scale, but that's not the issue here - but good to keep in mind for future playing.
The 1st one, which most call 'shape 1', is probably the first set that budding players learn. It is probably the most usable, and easiest, as it encompasses only 3 frets, making no need for any hand shifting for any notes. It also makes the blue notes easy to find, and bend into or out of.
The other consideration with all the shapes is hammering on, and pulling off. These operations need to happen (generally) on the same string. So it becomes apparent that with, say, shape 1, there are only certain pairs of notes which can be either hammered on or pulled off - those two on each string. That's fine, but what if you want to play the same thing with two notes that are not on the same string?
That's where the alternative shapes come in to play, so to speak. They reveal the opportunities to hammer on/pull off between the notes that the lower or higher shape denies.
There's also the slide possibility: sliding up or down will probably use the same finger on a string, and will therefore take you out of one shape into the neighbouring one. Yes, fingers can be swapped, but it's much smoother sounding using the same one. So then you're in the next shape, and that will (more or less) fall under your hand again. Maybe not so conveniently, but o.k.
You'll have seen that each shape, separated, joins up with the net - the high frets of one are the low frets of the next up. So it's more a question of building from one shape to another rathe than learning 5 different shapes. Shape 3 is the awkward one, having a 5 fret stretch, but that's not too much, really.
You are correct in saying move shape 1, for example, from 5th fret, where it's Am, to 6th fret where it's A♯m (more commonly B♭m), to 7th, where it's Bm, and so on.
Answer: Some good advice so far, but to be (sort of) clear on your questions:

The first diagram has the Root notes indicated with an R whereas the next 5 diagrams indicate the Root with the number 1 which is coloured orange. Root notes are the names of the key. If you play the first pattern at the 5th fret then all the notes indicated by an R in the first diagram, or an orange 1 in the next 5 pictures, are A notes.

The first diagram does not indicate frets 1 - 4, the 1st pattern can be played starting on any fret depending on which key you want to play in. Notice there are no dots marked in the diagram.
The first pattern (shape) is obviously the same as in the second picture, in this case the Root (the orange "1", which is a G note) is at the 3rd fret - you can tell because the double dots on the neck indicate the 12th fret. Therefore the scales as indicated are G minor pentatonic. The first pattern moved up two frets to where you play it makes it an A minor pentatonic.
The first diagram shows the same patterns as the next 5, in the same order, but they are not overlapped and instead shown separately to make them easier to view.
One simple way to see how the shapes connect is by the Root notes. In the pattern you know, the first octave (essentially the first half) of the scale would be played with the fingers 1 4 1 3 1 3 (some prefer 1 3 1 3 1 3 because they don't like using their pinky). So your 3rd finger would now be on the 4th string (D string) fret 7.
If you then place your 1st finger on the 4th string at the 7th fret where your 3rd finger was, you are in position to play the next pattern (also referred to as a shape)

Yes, you are correct A# (B flat) minor pentatonic.

Has been been answered a bit above.  I would add that different patterns will obviously move you higher or lower along the neck (fretboard) of the guitar allowing you to access higher or lower notes. Another way of saying this is that each pattern covers a different "range" of notes.

For example, playing pattern 4 by starting with your index finger on the 5th string (A string) at fret 12 would give you A minor pentatonic between frets 12 - 15 and you could play much higher notes than at the 5th fret.
Aside from hammer-ons and pull-offs being different from one pattern to the next, sliding between the shapes is a very common way to connect them and sounds really good.
And I suggest not necessarily using a 5 fret stretch for pattern 3, you would start with your 4th finger on the Root which is on the 5th string and when you cross over from string 3 to 2 you shift your index finger up one fret, then there is no stretch involved. It's called a squeeze shift but that's probably not important yet, but it has advantages over stretching.
The best way to initially learn the patterns is not to start on the lowest note. It is to start on the lowest Root. Then play to the highest note of the pattern, back down to the lowest, and finally to return to the lowest Root.
Hope that helps and good luck!
Answer: What you have in your first picture is an e minor pentatonic scale. E means that the root note is E. Minor means that the "third" of the scale is a minor third. Pentatonic means that there are five notes per octave.
In the following picture, the root note E is colored green. In your E minor pentatonic scale chart, it is marked with the letter R for Root. The root note of the scale is the center of harmony for that scale.

The distance from any note to the next higher note of the same name, for example from an E to the next-higher E is one octave, twelve frets. You can play pentatonic scales even on one single string:

I recommend practicing on a single string, because that gets you familiar with the distances between scale degrees. In any minor pentatonic scale, starting from the root which is 0, there's first a jump of +3 frets, then two more to get +5, then +7, +10, +12 which gets you to the root note again. Or if you start from the high E and go left i.e. down, you get -2, -5, ... In other words, if you go 7 frets (semitones) UP from E you get a B note, and if you go 5 frets DOWN from E, you get B as well.
Scales being movable means that the same shape can be moved across the fretboard to obtain other scales with different root notes. In the following animation, we move the E minor pentatonic scale up five frets to obtain the A minor pentatonic scale. You move the E minor scale, it's not an E scale anymore.

The animation doesn't show it, but more notes come in from the left, to mirror what's happening to the right of the 12th fret. Everything repeats all over again exactly the same at the 12th fret, no matter what scale it is. In the following picture, there's the A minor pentatonic scale. As you can see, it's what you have in your first picture, but everything is moved five frets to the right, and wrapped around at the 12th fret.

Now look at the root note A on the highest string. What are the distances? They're the same as for any minor pentatonic. Root = A = 0, then +3 frets, +5, +7, +10 and repeat all over.
You select your root note according to the key of the tune you're playing. If the song is in E minor, you (normally) select the E minor pentatonic scale. If it's in A minor, you select an A-based scale. The root note is the center, the home base, the zero-point of your harmonic thinking. Key means the same thing - it's the harmonic center. "The song is in E minor" means that the harmony is centered on E as home base, and the "third" above E is a minor third.
Which position or "box" you select? Whatever you want or need for the melodic lines you play. What is comfortable, reachable, appropriate for what you want. If you want your lines to go higher, move to a position up on the neck to reach higher notes.
How did they construct the shape 1 to shape 5 boxes? Any minor pentatonic scale contains the following notes:

Root, 1st, i.e. "1" or "R" in the pictures
Minor 3rd, i.e. "♭3"
Perfect 4th, i.e. "4"
Perfect 5th, i.e. "5"
Minor 7th, i.e. "♭7"

And then it continues. The scale goes 1, ♭3, 4, 5, ♭7, 1, ♭3, 4, 5, ♭7, 1, ♭3, 4, 5, ♭7, 1, ... You take every scale note exactly once, and don't skip anything. Start from the lowest note inside each position.
Using "boxes" is not the only way to construct pentatonic scale patterns for playing. We can make a scale on only one string. This is what the E minor pentatonic scale looks like on just the E string:

Or you could make a scale by using three notes per every string. Here's A minor pentatonic with three notes per string.

Not very easy to play, but why not, that's a scale. To play a scale run, you go up or down, using every scale degree exactly once, not skipping any.
The full diagrams with the whole fretboard full of notes is also a scale diagram in a way, but with multiple instances of the same pitch. In the positional boxes, there is only one instance of each pitch. ...  5, ♭7, 1, ♭3, 4, 5, ♭7, 1, ♭3, 4, 5, ♭7, 1, ...
Comment: Thanks for the detailed answer. :D It will take me some time to fully process it.

But I was just wondering. Given diagram 1 in my question, how do I know which section represents a scale shape? Like I already knew how the box pattern looked so I knew that the first 4 frets (red box) are ones I need to focus on. But if I did not know that then how would I have known the boundary for the red box?
Comment: In other words, if I just see the diagram 1 (without the annotation boxes and numbers I added), how do I know what all notes to play to make a minor pentatonic scale? That diagram has many notes and obviously I do not want to play ALL of them in a scale.
Comment: @ParthTamane I'll add an explanation to my answer when I have time, but while waiting, play the E minor pentatonic as shown, only on the high E string. Up and down. Listen to it, and learn to hear what each step sounds like, and look at and how many frets you're jumping at each step. Run it up and down a few times and always END on an E, to make you notice it as the home note, the center of E scales.
Comment: @ParthTamane The gray chart in your picture is the _E minor pentatonic scale_. It is not A minor. Moving the scale means you move the dots and the whole thing, not just your hand. In A minor pentatonic, the "third" is a minor third, just like in all minor scales. The distance between any minor scale's root and its third is _three frets_, three semitones. For A minor scales the minor third is C, which is the 8th fret on the E string. Is there a C on the E minor pentatonic scale in your first picture? No there is not.
Comment: I see what you mean about this being a E minor pentatonic. Are you saying that because "The distance between any minor scale's root and its third is three frets, three semitones.", if I start at a fret, the minor pentatonic pattern will include the next 3 frets. So the pattern will have next 4 frets starting from current fret?
Comment: No, it will have the scale notes in pitch order, every one of them exactly once, not skipping any, not repeating any. Play it from the lowest note up - if the next sound is _lower_ in pitch, you picked the wrong note. It should go up all the time. Play the E string notes and listen. Make it like a song you remember. Sing together with the guitar notes.
Comment: Okay I see what you mean. Given the diagram 1 can can chose which notes to play such that it goes R 3 4 5 7. But on the final string in box pattern we end up with R 3. In that case should we be playing the final 3? Because we do not end up completing the full sequence. We instead go reverse with R 7 5 4 3.


Calculate p-value?

Question: I have calculated the OR by hand to be 5.85 and I want to evaluate the support in the data for a link between alcohol use and esophageal cancer by calculating a p-value and interpret it. How do I do that?
Comment: Can I ask you why you un-accepted my answer? It is correct. Was there anything missing?
Comment: Chi-square test for independence?
Comment: @StatisticsRat I had gone through the entering of data, etc in R by the time your comment popped up, so I just went ahead with the answer. I figured I was helping a fellow in the medical field. BTW, if user153200 got the answer, can you click on "accept"? Ty
Comment: @Antoni Parellada Don't worry. I was just too lazy for a more sophisticated answer. Glad you took the job. ;)
Answer: The expected counts in each cell are $>5$, allowing you to use a chi square test of independence. I use the Fisher test to get the OR.
<code>> m=matrix(c(386,29,389,171),nrow=2)
> dimnames(m)=list(cancer=c("yes","no"),alcohol=c("<40 g/day",">40 g/day"))
> addmargins(m)
      alcohol
cancer <40 g/day >40 g/day Sum
   yes       386       389 775
   no         29       171 200
   Sum       415       560 975
> chisq.test(m)

    Pearson's Chi-squared test with Yates' continuity correction

data:  m
X-squared = 79.623, df = 1, p-value < 2.2e-16

> fisher.test(m)

    Fisher's Exact Test for Count Data

data:  m
p-value < 2.2e-16
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 3.814237 9.212062
sample estimates:
odds ratio
  5.841632
</code>

Calculate p-value?


Is it possible to swap the order of integration of the following integral with quadratic bounds, but a non-convex region of integration?

Question: Is it possible to swap the order of integration on the integral
$$
     \int_{-1}^1 \int_{-x^2-1}^{x^2+1} f(x,y) dy dx
$$
using Fubini's theorem?  More generally, the above region of integration is non-convex.  Does non-convexity cause issues when trying to swap the order of integration?
Answer: Let $\chi_{+}$ be the characteristic function of $[0,\infty)$. Then you can write your integral as
$$
     \int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\chi_{+}(x^{2}+1-y)\chi_{+}(x^{2}+1+y)f(x,y)dydx.
$$
The functions $\chi_{+}(x^{2}+1\pm y)$ are jointly measurable in $x,y$. Assuming $f$ is also jointly measure, and that the product of these is absolutely integrable, then there's no problem to write the above as
$$
\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\chi_{+}(x^{2}+1-y)\chi_{+}(x^{2}+1+y)f(x,y)dxdy.
$$
The whole issue becomes finding a jointly measurable function which is 1 on the region in question and 0 otherwise.


How to open and read from an external text file in odoo?

Question: I want to open a .txt file using python in odoo and read its contents. Where should I place this .txt file for it to be opened.
What I tried,
I kept the file in the same directory as models.py and in models.py wrote the code to open the file,
try:
    logFile = open('log.txt', 'r')

but this file is not opened. Please help, where should I keep log.txt for it to be located, or can I set any path for models.py to understand where log.txt is?
Answer: I just found the solution, I set the absolute path to where the .txt file is found.
import os

path = os.path.expanduser('<absolute path to .txt file>')
logFile = open(path, 'r')

this worked.
Answer: This is Python Code may be help you:
with open("log.txt") as file:   # Use file to refer to the file object
    data = file.read()
    do something with data
    print data

File handling in Python See this link : http://pymbook.readthedocs.org/en/latest/file.html
Comment: I tried your code, it doesn't work either. There's no problem in the code, it's about where to place the file in odoo, for models.py to recognize it. Or at least to give a path to help models.py recognize where the .txt file is


Autoencoder processing whitened input

Question: I come across this when reading a UFLDL tutorial article where an autoencoder is used to learn the features of input data. Besides, the number of hidden-layer neurons is equal to the number of inputs. The thing is, input data is pre-processed using whitening transformation which is essentially PCA (see this). The purpose of this practice should be to make the training/optimization process easier (see this). Personally, I think PCA itself can be used as a feature learning algorithm by treating the identified principal components as features. What's done in the article then looks like

Learn features using PCA
Pre-process data based on the features learned by PCA
Learn features again using autoencoder based on the pre-processed data

There are thus two feature sets learned by PCA and autoencoder, respectively. Furthermore, the autoencoder is trained on data pre-processed using features identified by PCA. Since the number of hidden-layer neurons equals that of inputs, both feature sets have the same cardinality. My questions are

What are the characteristics of the two feature sets learned by autoencoder and PCA? A trivial fact is that features learned by PCA are orthogonal, which is not necessarily true for autoencoder.
What are the potential interaction effects I should be aware of by doing what's done in the article? I already know that whitening pre-processing is supposed to make the training process afterwards easier.
Or is my understanding totally wrong from the very beginning?

Related threads:

Is using PCA then autoencoders for pre-processing useful?
Does it make sense to implement a PCA after an Autoencoder processing?
Comment: See this thread: https://stats.stackexchange.com/questions/145071/why-do-we-need-pca-whitening-before-feeding-into-autoencoder
Comment: @AlexR. After reading what you linked, I came up with something and have written up an answer myself.
Answer: After reading this thread referred to by @AlexR., I seem to figure it out myself.
First of all, using PCA as a feature learning algorithm may not be very useful. It's systematic, and thus dull in some sense. In fact, whitening transformation doesn't have to be PCA at all (which is PCA whitening), and simply identifying a set of orthogonal coordinates isn't really feature learning. It's better to just treat it as a pre-processing algorithm here. This invalidates my first question.
Now to answer the second question. For images, it's not difficult to realize that adjacent pixels are correlated. They tend to be similar. Besides, distant pixels tend to be different. I guess this is what the following has said in plain language (quoted from this thread).

Natural images have a lot of variance/energy in low spatial frequency
  components and little variance/energy in high spatial frequency
  components.

In terms of autoencoder, this means inputs that correspond to adjacent pixels are positively correlated. The effect is that autoencoder tends to learn the big picture while omit the details (see this). An explanation from spatial frequency perspective is:

When using squared Euclidean distance to evaluate the reconstruction
  of an autoencoder, this means that the network will focus on getting
  the low spatial frequencies right, since the error scales with the
  variance of the signal.

Another intuitive explanation I came up with myself is like this: It's easier to attain a lower cost function value if you focus more on the big picture, and ignore the details. This is because adjacent pixels tend to be similar, you get one right, then you get all right mostly. That is, when the big picture error is low, the details error tends to be low as well. The converse doesn't hold.
By applying the whitening transformation, this correlation and variance difference are eliminated, and the learning process pays equal attention to both the big picture and details. And according to this article, this usually results in a more effective training/optimization process, and a lower error in terms of both the big picture and details.
To conclude

Whitening transformation is not PCA.
In this context, it's simply a pre-processing algorithm that regulates the data, and nothing more.

Autoencoder processing whitened input


Question on linear algebra-matrices

Question: Let $A$ be an $m\times n$ matrix and $B$ an $n\times k$ matrix. Show that the
columns of $C=AB$ are linear combinations of the columns
of $A$. If $\alpha_1,\dotsc,\alpha_n$ are the columns of $A$
and $\gamma_1,\dotsc,\gamma_k$ are the columns of $C$,
then:
    $$\gamma_j=\sum\limits_{r=1}^{n}B_{rj}\alpha_r$$
Please help me in this problem, I have no idea how to solve this.
Comment: You are nearly there but in fact $$\vec{\gamma_j}=\sum\limits_{r=1}^{n} B_{rj} \ \vec{\alpha_r}.$$  If you can show that then you are done
Answer: The columns of $C$ are given by $C e_k$, where $e_k$ is the $k$th unit vector. (So we have $\gamma_k = C e_k$, $\alpha_r = A e_r$.)
I use $[A]_{ij}$ to mean the $i,j$ entry of $A$.
Note that with this notation, $C e_k = \sum_i [C]_{ik} e_i$ (ie, $ [C e_k]_i = [C]_{ik}$).
Hence $C e_k = AB e_k = A \sum_i [B]_{i k} e _i =\sum_i [B]_{i k} A e_i$.
So, in your notation, $\gamma_k = \sum_r [B]_{r k} \alpha_r$.

Question on linear algebra-matrices


use controller in helper

Question: In my cakephp application i need to use my controller in helper.php. Its not working. will any one explain it with little syntax?
Comment: Are you using version 1.1 or 1.2?
Answer: I really hate thinking that code can tell me how to think instead of me telling it what to do ... anyway ... here is an example for loading the controller rendering the page, and it can load any controller inside the helper.
<code><?Php
class HelperNameHelper extends AppHelper{

    private $controller;

    public function __construct(View $view, $settings = array()) {
        parent::__construct($view, $settings);

        $this->controller=$this->loadController();

    }

    protected function loadController($name=null){
        if (is_null($name)) $name=$this->params['controller'];
        $className = ucfirst($name) . 'Controller';
        list($plugin, $className) = pluginSplit($className, true);
        App::import('Controller', $name);
        $cont = new $className;
        $cont->constructClasses();
        $cont->request=$this->request;
        return $cont;
    }
}
</code>
EDIT: just realiced this is such an old post :( ... this is working in cakephp 2.2.3
Comment: +1 for ***I really hate thinking that code can tell me how to think instead of me telling it what to do*** Although it must be always noted that the conventions exist for a purpose. If you absolutely understand what you are at and what is at stake, this is a good example of manipulating the conventions for greater benefit. BTW, `App::import()` exists for developers who understand what they are doing, else it simply wont exist. Others probably advocated conventions to stop newbies from exploiting methods without understanding the side effects.
Comment: rules are meant to be broken :P
Answer: Helpers are not designed to have access to the controller.  If you're trying to access the controller you may want to rethink your application design.
I actually had this same problem myself.  I have a CakePHP 1.1 application where I was accessing the controller by passing the name of the controller as a parameter to the view.  After trying to upgrade the code to work with 1.2 I realized that this was bad design.  It was my first experience with CakePHP and MVC, so I chalked that up as a lesson learned.
MVC requires some up-front design to make sure that you're putting your functions in the right places (controller, model, or view).
(P.S. You can also try the #cakephp channel on irc.freenode.net)
Answer: Its an MVC.
You shouldn't use a Controller in your helper, rather use your helper in your controller.
Why would wan't to do that in the first place.
Read this:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

use controller in helper


How to find the correct orthogonal eigenvectors for a basis of an eigenvalue?

Question: I have an exercise where I found the two correct eigenvalues $\lambda_{1} = 0$ and
$\lambda_{2} = 6$.
The algebraic multiplicity of $\lambda_{2}$ is 2. Now I try to find $E_{\lambda_{2}}$ with the following matrix. I've already done the elementary operations needed to solve the system.
$(A-6I | 0) = \begin{pmatrix}
1 & 1 & -2 \\
0 & 0 & 0  \\
0 & 0 & 0  \\
 \end{pmatrix}$
Now we get the following system of linear equations.
$x+y-2z = 0$
$y = y$ (first free variable)
$z = z$ (second free variable)
This basically implies that $x = -y +2z$
So, to get my eigenvectors of my basis I do:
$\begin{pmatrix}
 x \\y\\z
 \end{pmatrix} = \begin{pmatrix}-1\\1\\0 \end{pmatrix}y +
\begin{pmatrix} 2\\0\\1 \end{pmatrix}z$
therefore $E_{\lambda_{2}} = \bigg\{ \begin{pmatrix}-1\\1\\0 \end{pmatrix} ,
\begin{pmatrix} 2\\0\\1 \end{pmatrix} \bigg\}$.
However, this not what the solution in my textbook is even though we had the same exact matrix.
They have as solution that $E_{\lambda_{2}} = \bigg\{ \begin{pmatrix}1\\-1\\0 \end{pmatrix} ,
\begin{pmatrix} 1\\1\\1 \end{pmatrix} \bigg\}$.
I know that they are different vectors which you can take by multiplying the vectors found in the linear equation $\begin{pmatrix} x \\ y \\ z \end{pmatrix} = ()y + ()z$ by some scalar.
For example I could do
$-1\begin{pmatrix} -1\\1\\0 \end{pmatrix}$ = $\begin{pmatrix} 1\\-1\\0 \end{pmatrix}$ which gives me the first vector they had in their solution.
However, I don't get how they got $\begin{pmatrix} 1\\1\\1 \end{pmatrix}$ as their second vector of the basis. Where did I went wrong?
While writing the question I realized that in the end both my solution and theirs are correct however their solution has the advantage of proposing two orthogonal vectors that are orthogonal with the basis of $E_{\lambda_{1}} = \bigg\{\begin{pmatrix} 1\\1\\-2 \end{pmatrix}\bigg\} $ without resorting to doing Gram-Schmidt afterwards.
So now, I want to know what was the method used to get those orthogonal vectors easily is there a process or was it just trial and error?
Comment: could you be a little more specific? of course you can choose whatever you want for y and z, but in this case it's easy to see that we get orthogonal vectors if we choose them this way. why? well the first vector has a 1, a -1 and a zero. so the third coordinate is of no interest. we only want the first and second coordinate to be the same, so they cancel out if we take the scalar product.
Comment: since you can choose 2 eigenvectors, you get the first by setting y=-1 and z=0 like you suggested yourself. you get the other one by setting y=z=1
Comment: why do you do y=z=1?
Answer: If you just want a vector that satisfies $x=-y+2z$ and is orthogonal to $\begin{pmatrix}-1\\1\\0\end{pmatrix}$, then solve $x=-y+2z$ and (from the dot product being $0$) $-x+y=0$. You'll find that $x=y=z$ and then might as well pick $\begin{pmatrix}1\\1\\1\end{pmatrix}$. As you mentioned, if you wanted an orthonormal basis, Gram-Schmidt is a process you could follow.
Answer: There is nothing wrong with the basis vectors that you have found. As you know basis for a vector space is not unique even if you orthogonalize your basis your solution may be different from the book's answer. You may use Gram-Schmidt process for togonalization of your basis.
Answer: Applying Gram-Schmidt without normalization to your two vectors gets you $(1,1,1)^T$. Not having seen your original matrix, having this as an eigenvector means that the rows all sum to zero, so you might've found this one without going through any of the other work.


How to write a static event emitter in GDScript?

Question: Godot doesn't support static signals, so I tried two approaches:
Empty Signal:
static var my_signal: Signal = Signal()

Custom type:
static var my_signal: StaticSignal = StaticSignal.new()

class_name StaticSignal

var _callables: Dictionary

func connect(callable: Callable) -> void:
    self._callables[callable] = true

func disconnect(callable: Callable) -> void:
    self._callables.erase(callable)

func emit(data: Variant) -> void:
    for callable in self._callables:
        callable(data)

The problem is when it comes to .connecting to the signal. With StaticSignal I am getting a .connect member not found error. With Signal I am getting an ignored runtime error.
static func _static_init():
    ChatLog.new_message.connect(func(msg):
        if len(_log) >= LIMIT:
            _log.remove_at(0)
        _log.append(msg))

Answer: I will show two approaches: one on how to create static signals and the other on arguably the "expected" approach.
Static Signals
Godot doesn't support the keywords to define a static signal. However, we know that when we load() or preload() some gdscript we get a container resource object of type GDScript. A gdscript with a class_name is symbolically bound to a GDScript.
The gdscript parser has a sort of special treatment of these symbols. We can bypass that. Since the the symbol is actually backed by a GDScript object we can cast it to GDScript or an ancestor. Then we can add our static signals to the GDScript resource that the class name is bound to.
Additionally, Godot 4 handles circular dependencies with class_names so this pattern actually possible.
The script with static signals:
extends Node
class_name StaticSignalsClass

static var static_signal_1: Signal = (func():
    # We have to manually add a user signal.
    (StaticSignalsClass as Object).add_user_signal("static_signal_1")
    # Now return a reference to the signal we just defined.
    return Signal(StaticSignalsClass, "static_signal_1")
).call()

# We can also define a helper static method:
static func make_signal(p_obj, p_signal_name: StringName) -> Signal:
    # We use GDScript's duck typing to avoid having to cast p_obj.
    p_obj.add_user_signal(p_signal_name)
    return Signal(p_obj, p_signal_name)

static var static_signal_2: Signal = make_signal(StaticSignalsClass, "static_signal_2")

The client script:
static func _static_init():
    StaticSignalsClass.static_signal_1.connect(func(): print("Hello, ss1."))
    StaticSignalsClass.static_signal_2.connect(func(): print("Hello, ss2."))

# Somewhere else...
func emit_stuff():
    StaticSignalsClass.static_signal_1.emit()
    StaticSignalsClass.static_signal_2.emit()

"Expected" Signal Center
We define an autoload that is the center for our signals. You can create namespaces by

Adding a property that holds a script with more signals.
Follow the RenderingServer pattern with the namespace in the name.

The caveat is to be mindful of the order autoloads are loaded. If an earlier initialized autoload accesses SignalCenter it will fail. (However, on _ready will work.)
extends Node
# autoload name: SignalCenter

signal chatlog_new_message(msg: String)
signal chatlog_user_joined(guest_id: int)
signal chatlog_user_left(guest_id: int)

# Or

var chatlog := ChatLogSignalCenter.new()

### ChatLogSignalCenter script

extends Object

signal new_message(msg: String)
signal user_joined(guest_id: int)
signal user_left(guest_id: int)

The client script:
extends Node
class_name StaticClient

static func _static_init():
    SignalCenter.chatlog_new_message.connect(func(): print(msg))

    # or

    SignalCenter.chatlog.new_message.connect(func(): print(msg))


Asymmetric periods in a sine curve

Question: I am wondering how to graph an asymmetric sine wave so that the slope of one side of the parabola is larger than the other, much in the same way as a sine graph with decreasing frequency. However I was wondering if there was a method to graph it so that the frequency does not continue to decrease, but is instead the same asymmetric shape throughout.
Answer: If you mean that you want a periodic function whose period looks like a "distorted" sine, you can do that by altering the argument to sine. Normally we look at $\sin (t)$, where $t$ increases steadily. But if we alter this slightly, we can take $\sin (s(t))$, where $s(t)$ has a graph that looks like the graph of $t \mapsto t$, but slightly distorted. A good example:
$$
t \mapsto \sin ( t + 0.2 \sin t)
$$
Graph:

Same idae, but with $0.2$ replaced by $0.5$:
Answer: $$\sin\left(x+\frac{1}{2}\sin(x)\right)$$
is an example of the type of curve that you seem to be looking for

Asymmetric periods in a sine curve


pcl::MovingLeastSquares doesn't work

Question: I'm new to PCL and I'm trying to do this tutorialhere. The problem is that I can compile it, but when I run this, it give me an error: *exception at 0x000007fefd27940d in pcl_VFHexperiment.exe: Microsoft C++ exception: pcl::IOException at memory location 0x001cf0e0*
I guess the problem is that mls. process function doesn't work correctly and the operation of file saving provides an error.
Could be the input file the problem? I use ism_test_cat.pcd file found here. I don't know where the file suggested in the tutorial is. How should the input file be?
Anyway I can see ism_test_cat.pcd file in the viewer following the other tutorial.
How to solve? Please help me.
I use VS2010, PCL 1.6, all 64bit
Thanks in advance a lots
Answer: "You should be able to find the input file at pcl/test/bun0.pcd." It says in the tutorial.
Comment: [Google'd it and found it here] (https://code.ros.org/trac/ros-pkg/browser/stacks/point_cloud_perception/trunk/pcl/test?rev=28203)
Comment: I've just tried it, it doesn't work! It returns the same error! How could I solve this? Thank you very much!!
Comment: Hmmm ... I'm working on Ubuntu so I don't really know in you're case what could be the problem. Can you try it with another .pcd files from one of the exercises and come back?
Comment: thank you. I tried also with other ASCII files but nothing. Always the same problem. Should I try with binary files? I don't know where I can find it. Anyway, I noticed that error arises when it executes line 'pcl::io::savePCDFile ("bun0-mls.pcd", mls_points);' and not before
Comment: hmmm then can you check if you save the rigth thing, whatch out for the references. PCL sadly has manny tricks that hardens the use of it.
Comment: I've just tried to change file saving mode to 'savePCDFileASCII' and now it doesn't return an error. The file saved is different from input, probably there is information about normals. I don't know how to visualize it. But why  does 'savePCDFile' not work?
Comment: Can you re read? Use Rviz for visualising or pcl::visualizer!
Comment: My final purpose is to get meshes from point clouds. I don't still succeed. I am following this [tutorial](http://www.pointclouds.org/assets/icra2012/surface.pdf) but it doesn't work because it is not clear what is the input for pcl::MovingLeastSquares::process. For me it is not clear how to pass from 'PointXYZ' to 'PointXYZRGB' and so on.
Comment: Trying again with my original file [ism_test_cat.pcd](https://github.com/PointCloudLibrary/data/tree/master/tutorials) I received a new error when pcl::MovingLeastSquares::process function runs: 'Debug Error! Program:...  R6010-abort() has been called'. I'm using this settings: 'mls.setComputeNormals (true);
  mls.setInputCloud (cloud);
  mls.setSearchRadius (0.5);
  mls.setPolynomialFit (true);' What's on now?  Thank you
Comment: This is my [code](http://justpaste.it/dd14) which doesn't work as explained above
Comment: Also give at least a vote up for the response, if I helped you in any way.
Comment: I strongly wish, but I can't because it requires 15 reputation

pcl::MovingLeastSquares doesn't work


Nginx disable .htaccess and hidden files but allow .well-known directory

Question: I have a Nginx server, and disabled hidden files in the nginx_vhost.conf
## Disable .htaccess and other hidden files
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

But LetsEncrypt needs access to the  .well-known directory.
How do I allow the .well-known directory and deny the other hidden files?
Comment: Note: nginx does not use or have `.htaccess` files. It has configuraiton files but they aren't called `.htaccess`, nor do they work the same.
Comment: @Rob it's not that nginx uses .htaccess files... it's in case you are moving from apache to nginx and you don't want nginx to serve the content of .htaccess files... and you don't want to move or delete the .htaccess files yet either
Answer: The other solutions did not helped me.
My solution is to include a negative regex for .well-known. Your code block should look like this then:
## Disable .htaccess and other hidden files
location ~ /\.(?!well-known).* {
    deny all;
    access_log off;
    log_not_found off;
}

It will block every dot file except the ones starting with .well-known
P.S.: I would also add return 404; to the block.
Comment: no it's not the same exactly. `/\.(?!well-known\/)` is not as expressive as my regex (because I block all dot files except well-known by definition). Maybe the best would be a combination like `location ~ /\.(?!well-known\/).*` which unblocks only the well-known directory instead also a theoretical `.well-known-blabla`. But I think there is no real danger in not blocking a theoretic .well-known-blabla file.
Comment: Yes you're right @webwoman but sometimes there are mixed environments. Any dot file should not be served in my opinion (security or unwanted exposing of history like with .git) unless really needed.
Comment: Is `location ~* /\.(?!well-known\/) {` as seen at https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/protect-system-files.conf identical to this `location ~ /\.(?!well-known).* {`  ?
Comment: why disable htaccess since anyway Nginx doesn't handle it ?
Answer: Nginx applies locations with regular expressions in the order of their appearance in the configuration file.
Therefore, adding an entry like this just before your current location it will help you.
location ~ /\.well-known {
    allow all;
}

Comment: Thank you, this is exactly what I needed! Placed this before a rule denying access to all dotfiles. Only thing I changed was escaping the dot, e.g. `location ~ /\.well-known {`. Either way, this should be the accepted answer.
Answer: I've provided a full step by step tutorial on how to use Let's Encrypt with NGINX on my website.
The key parts are:

The official client is only ok, and is really poor on Amazon Linux. I recommend a different client, ACME.
Use this location for the webroot method, with my recommend client. Note that the requests are served over http, not https.

You don't need listeners in your https block at all, it's all done on https. This is only to prove you control the domain, it's not serving anything private or secret.
# Answer let's encrypt requests, but forward everything else to https
server {
  listen       80;
  server_name  example.com www.example.com
  access_log  /var/log/nginx/access.log main;

  # Let's Encrypt certificates with Acmetool
  location /.well-known/acme-challenge/ {
    alias /var/www/.well-known/acme-challenge/;
  }

  location / {
    return       301 https://www.example.com$request_uri;
  }
}

Full step by step guide linked above.
Answer: Add this (before or after):
location ^~ /.well-known/ {
        log_not_found off;
     }

You can add this also at bottom, because the matching ^~ modifier takes precedence over regular expressions.
See the the docs.
Answer: If you have lots of config files and they already contain a deny on .htaccess like
location ~ /\.ht { deny all; }

then instead of ignoring all dot files, you can simply add a second ignore for .git with
sed -i '/location ~ \/\\.ht { deny all; }/a \  location ~ \/\\.git { deny all; }' /etc/nginx/*


Multiplicação recursiva em C

Question: Estou aprendendo recursividade em C, e consegui fazer alguns programinhas usando a recursividade. Entretanto, estou apanhando para fazer um simples programa que o usuário mandando dois números, exemplo: 6x2, eu os multiplico em recursão. Posso até mostrar o código abaixo, mas tenho certeza que ele foge totalmente da realidade do real código.
Code:
#include <stdio.h>

int poligono(int n,int v){
    int res=0;

    if(v==0)
        return 0;
    else if(n==0)
        return n;
    else
        return n + poligono(n,v);
}

int main(){

    int n,v,res=0;
    scanf("%d%d",&n,&v);
    res=poligono(n,v);
    printf("Res = %d\n",res);

    return 0;

}

Comment: que tal utilizar main como deve ser utilizado para ver se compila? Use: int main() { /*seu código...*/ return 0; }
Comment: Para perceberes o que está mal, pega em 2 números quaisquer e faz a recursividade à mão num papel. Vais conseguir ver o teu problema.
Comment: Fora que teu código gera uma recursividade infinita, logo seu código gera um erro chamado (acho que você já ouviu falar, rsrs) Stack Overflow. Pois excede o limite de chamadas "empilhadas" na pilha (stack).
Comment: Bruno, peço-lhe desculpas, pois o código que não compilava era outro. Esse compila. Logo vou editar minha pergunta.
Comment: @Fiodor faz o que eu te disse, pega em 2 números e percorre a função recursivamente, mas vai escrevendo no papel e vais entender onde está o teu problema.
Comment: Seguirei seu conselho, @JorgeB.
Comment: @Fiodor eu reverti a sua pergunta, para que as respostas que já tinha não ficarem invalidas. avisei o Math também para editar a resposta dele.
Answer: Alguns pontos a melhorar:

A verificação no primeiro if é desnecessária, você precisa tratar o n que é o número de vezes que o seu código é iterado, nunca o v, que deve ser um valor fixo a ser somado com ele mesmo por n vezes.
Nunca se deve retornar n, somente v.
O valor de n deve ser decrementado a cada iteração, ou incrementado, caso n seja um valor negativo.
No seu algoritmo não são tratados os valores negativos.

Juntando tudo isso:
#include <stdio.h>

int poligono(int n, int v){
    int vs;
    if(n>0){
        n--;
        vs = v;
    }
    else if (n<0){
        n++;
        vs = -v;
    }

    if(n==0)
        return vs;
    else
        return vs + poligono(n,v);
}

int main(){

    int n,v,res=0;
    scanf("%d%d",&n,&v);
    res=poligono(n,v);
    printf("Res = %d\n",res);

    return 0;

}

Veja um exemplo no Ideone: https://ideone.com/XjxKnG
Comment: originalmente não havia o "n - 1", ele editou a pergunta após meu comentário acima,,,
Comment: Era isso mesmo, obrigado. Entretanto, só fui ter consciência de que tinha de ter um decremento ali devido aos usuários acima.
Comment: @JoséX. ah tah, não acompanhei todo o histórico da evolução da pergunta, mas foi um ponto importante a se corrigir.
Comment: Math eu reverti a pergunta, para não ser camaleônica, se quiseres editar a resposta...
Comment: @JorgeB. agora que vi o histórico da edição, tem bastante coisa lá hein? rs..
Answer: Primeiro, uma questão que tem que ser obedecida na recursividade é que ela seja finita, ou seja, tem que existir uma saída do seu programa. Se você quer fazer uma multiplicação recursiva, faria desse jeito:
int poligono( int a, int b ){

   if( b == 1)
     return a;
   return a + poligono(a, --b);
}

Answer: Um algoritmo recursivo sempre pressupõe a utilização do mesmo algoritmo em um problema mais simples, até que eventualmente o problema é tão simples que não é mais necessário usar recursividade.
No seu exemplo, a linha
   return n + poligono(n,v);
deveria ser
   return n + poligono(n-1,v);
Note que nem estou analisando se seu programa funciona corretamente, estou apenas resolvendo o problema da recursividade infinita.
(Estou também assumindo que eventualmente você colocará alguma consistência para evitar o uso de valores negativos.)
Comment: Não entendi a sua primeira frase, quer dizer que o algoritmo recursivo nunca deveria existir em produção?
Comment: @Math "problema mais simples" na verdade deveria ser "sub-problema mais simples"; no caso em questão é quando n == 0; concordo que o texto não está muito claro, escrevi apressadamente e depois não quis editar
Comment: Ah tah, agora entendi. Bom, se editasse poderia deixar a resposta mais completa, de qlq forma ai vai meu +1
Answer: O método recursivo para a multiplicação de dois fatores é 3+3+3+3=11:
primeiro pense em como é feita a multiplicação.
34=11 é o mesmo que 3 + 42 que significa o mesmo que 3 + (4*(3-1)) recursivamente
int poligono(int a , int b) {
        if ((a == 0)||(b==0))
        {
            return 0;
        }
        else {
            return a + poligono(b,(a-1));
        }
    }

Comment: 3+4*2 dá 11, e não 12

Multiplicação recursiva em C


`auth_data=': couldn't set additional authenticated data

Question: I am new on RoR and created a new project with all configurations of ruby and rails.
I have

mac version 12.4 Monterey
rails 6.0.5
ruby 2.7.2
postgresql

I configured these using rbnev from this tutorial https://gorails.com/setup/osx/12-monterey  and https://collectionbuilder.github.io/cb-docs/docs/software/ruby_mac/
I created new app using rails new myapp -d postgresql. It's showing this error while building the project:
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/message_encryptor.rb:173:in `auth_data=': couldn't set additional authenticated data (OpenSSL::Cipher::CipherError)
    from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/message_encryptor.rb:173:in `_encrypt'
    from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/message_encryptor.rb:151:in `encrypt_and_sign'
    from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/encrypted_file.rb:76:in `encrypt'
    from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/encrypted_file.rb:50:in `write'
    from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.5/lib/active_support/encrypted_configuration.rb:29:in `write'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/generators/rails/credentials/credentials_generator.rb:30:in `add_credentials_file_silently'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/generators/rails/app/app_generator.rb:177:in `credentials'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/generators/app_base.rb:155:in `build'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/generators/rails/app/app_generator.rb:332:in `create_credentials'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/commands/application/application_command.rb:26:in `perform'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Library/Ruby/Gems/2.6.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/command/base.rb:69:in `perform'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/command.rb:46:in `invoke'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/lib/rails/cli.rb:18:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:65:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:65:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/railties-6.0.5/exe/rails:10:in `<top (required)>'
    from /usr/bin/rails:22:in `load'
    from /usr/bin/rails:22:in `'

Comment: i have rails 6.0.5 but when i try to uninstall the rails by using "gem uninstall rails" it's showing: Gem 'rails' is not installed
Comment: Try to reinstall rails gem in your device. that may help you and let me know what happend...
Comment: @AbrarJahin it's showing me the rails version but don't have any local gems rails in my system
Comment: Did you tried to run `gem install rails` command again after getting the `Gem 'rails' is not installed`
Comment: yes i tried this command but it gives me this --> ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
Answer: According to your issues on MAC device for ROR, You might be facing the issues because of versioning system and rbnev, and I got an article over the internet that described the same issue with some solutions.
Maybe this article will help you to fix that problem
If you can fix the issue from the article then let me know here too.
Comment: it resolved with the help of this : https://stackoverflow.com/questions/10940736/rbenv-not-changing-ruby-version
Comment: Thank you for your response but i checked this article before but it's not working for me


Must a matrix of sample pairwise covariances be PSD?

Question: Consider a random vector $\mathbf{X}=(X)_{i=1}^n$. Then the covariance matrix $$C=\mathbb{E}[(\mathbf{X}-\mu(\mathbf{X}))(\mathbf{X}-\mu(\mathbf{X}))^\top]$$ is by definition positive-semidefinite.  (The random components in my case of interest all have unit variance and zero mean, so $C$ is also the correlation matrix). Moreover the same is true, up to numerical sensitivity, for a sample covariance matrix (e.g. this answer).
My understanding, however, is that this assumes each sample measures all $n$ components of the random vector. Suppose instead that each sample is pairwise i.e. only two of the components are measured. In that case, we can still compute the sample covariance between any two components by considering only those measurements which contained them. Is the resulting matrix of sample pairwise covariances still guaranteed to be PSD?
My suspicion would be that this represents an extreme case of 'partial pairwise deletion' and therefore one may certainly lose the PSD property. But I have little intuition for how sensitive the PSD condition is and so would appreciate more detail. For instance, in my case of interest the choice of pairs is not random and I can thus ensure that each pair has the same sample size; does this make a difference in whether the PSD property is preserved? I'd also be interested in the numerical sensitivity of such.
Comment: Intuitively, the loss of the PSD property depends on how "close" $C$ is to becoming indefinite.  There is no guarantee.  The sensitivity depends on so many factors, including $C$, how you sample, and how you choose to estimate the coefficients, that it's difficult to imagine doing anything more effective than performing your own sensitivity analysis to assess the particular circumstances you face.
Answer: If you only have pairwise samples, the sample covariance matrix need not be PSD any more.  A trivial example in R follows:
<code>x <- matrix(rnorm(36), 12, 3)

cov_x <- matrix(0,3,3)

# We observe x1 and x2 for observations 1...4
# We observe x1 and x3 for observations 5...8
# We observe x2 and x3 for observations 9...12

cov_x[1,1] <- var(x[1:8,1])
cov_x[2,2] <- var(x[c(1:4,9:12),2])
cov_x[3,3] <- var(x[5:12,3])
cov_x[1,2] <- cov_x[2,1] <- cov(x[1:4,])[2,1]
cov_x[1,3] <- cov_x[3,1] <- cov(x[5:8,])[3,1]
cov_x[2,3] <- cov_x[3,2] <- cov(x[9:12,])[3,2]
</code>
I ran this ten times and seven of them generated a negative eigenvalue, for example:
<code> > eigen(cov(x))$values
[1] 1.1456649 0.8638590 0.7980396
> eigen(cov_x)$values
[1] 1.6430049  0.8456930 -0.2898667
</code>
If you want a PSD covariance matrix estimate, you can treat this as a missing data problem and construct such estimates in any of several ways, see for example the answer and comments to covariance-matrix-estimation-in-presence-of-missing-data.


Simplifying an unusual quadratic linear algebra expression

Question: I came across the following expression when solving a maximisation problem. I have the following ingredients:

Matrices $\Omega, P \in \mathbb{R}^{n \times n}$
Vector $t \in \mathbb{R}^n$
Also let $\mathrm{diag}(x), x \in \mathbb{R}^n$ denote the diagonal $n \times n$ matrix whose diagonal entries are the components of $x$, $\mathrm{tr}$ be the trace of a square matrix and $\cdot$ denote usual matrix-algebra multiplication

Now, I have the following expression:
$$X = \mathrm{tr} \left( \Omega \cdot \mathrm{diag}(t) \cdot P \cdot \mathrm{diag}(t) \right) $$
So it seems to me that the expression is quadratic in vector $t$, linear in $P$ and $\Omega$ - so I would expect (hope?) that it can be written as
$$ X = t^T \cdot f(\Omega, P) \cdot t $$
for some function $$f : \mathbb{R}^{n \times n} \times \mathbb{R}^{n \times n} \rightarrow \mathbb{R}^{n \times n}$$
which is also hopefully is expressible as something simple (linear). Is this right? If so, how can I get there? Or perhaps there are some other simplifications to this effect?
Any help, including pointers, is highly appreciated.
Answer: The $ik$ element of the thing inside the trace is
$$
\omega_{ij} t_j P_{js} t_s
$$
with a sum over $j$ and $s$. The trace is the sum of the $ii$ elements, hence
$$
\omega_{ij} t_j P_{ji} t_i
$$
summed over $i$ and $j$, which is
$$
\sum_i \sum_j t_j \omega_{ij}P_{ji} t_i
$$
That has the form you required, with $U = f(\Omega, P)$ being a matrix whose $ij$ element is
$$
u_{ij} = \omega_{ji}P_{ij}.
$$
Comment: Awesome - thank you so much!


XML in Classic ASP Vbscript

Question: I am back to asp with XML manupulation.
Initial file:
<?xml version="1.0" ?>
<root>
  <sport/>
</root>

this is my function
Public Function DefinitFunction( x,z)

Dim text
Dim Root
Dim NodeList

    text = "<Definition>" ---<x> </x> <z> </z> --</Definition> "
    text = text & "<x><![CDATA["&x&"]]> </x>"
    text = text & "<z> </z>"
    text = text & "</Definition>"

Set Root = objDoc.documentElement
Set NodeList = Root.getElementsByTagName("sport")

NodeList.appendChild text

objDoc.Save strFile

end function
'  Private strFile, objDoc are class object

I want to modify the all thing dynamically. So I have a function :
DefinitFunction(x,z) that will concatenate a string and append <Definition> ---<x> </x> <z> </z> --</Definition> in my file right after the Node <sport>
at the end this should be my result:
<?xml version="1.0" ?>
<root>
  <sport>
    <Definition>
        ---<x> </x> <z> </z> --
      </Definition>
   </sport>
</root>

This is not working. Is there any better way of accomplishing this?
Comment: Its not entirely clear from your code sample, but are you using the MSXML object or something else?
Answer: You cannot append text directly .. you need to convert it to XML node first..
Set newXML = CreateObject("Microsoft.XMLDOM")
newXML.async = False
newXML.loadXML( "<root>" & text & "</root>")

NodeList.appendChild( newXML.documentElement.selectSingleNode("/Definition"))

Comment: do not use `Root.getElementsByTagName("sport")` to get to sport.. use `Root.selectSingleNode("sport")`. The first returns a node list (*to which you cannot append directly*) the second returns a node (*which supports the appendChild..*)
Comment: Nope
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'NodeList.appendChild'
Comment: This is a plus.thanks. However it append outside of the sport node
 ---    --
instead of
  ---    --
Comment: All good. my bad
It all good
Thanks for your help
from the future expert in xml -asp
Comment: no problem ZAfrican .. have fun with xml ;) (*you should go back to your questions and accept answers if they were helpful .. this will make people more eager to answer your future questions..*)

XML in Classic ASP Vbscript


Question about the number of combinations with repetition

Question:
Suppose that you have a set of $12$ colored balls, two each of six different colors $C_1$ through $C_6$. Find the number of six-ball combinations if balls of the same color are considered identical.

I think the problem quoted above is identical to the one in this question. In both problems we are counting combinations of length six with repetition. Each combination in both problems contains at most two copies of the same element, so the answer to my problem must be $141$ as well. Is this correct?
Answer: Your reasoning is correct, the answer is indeed 141. However, I would solve this problem in a more straightforward way. Since every color can occur at most two times, one should simply consider the following cases:

Combinations of $(1, 1, 1, 1, 1, 1)$: ${6 \choose 6} = 1$ option;
Combinations of $(2, 1, 1, 1, 1)$: ${6 \choose 1} {5 \choose 4} = 30$ options;
Combinations of $(2, 2, 1, 1)$: ${6 \choose 2} {4 \choose 2} = 90$ options;
Combinations of $(2, 2, 2)$: ${6 \choose 3} = 20$ options.

As such, there are $1 + 30 + 90 + 20 = 141$ valid combinations.


Bound on order of commutator subgroup of a $p$-group

Question: I was reading an article where it is claimed that

If $G$ is a finite $p$-group with $|G|=p^n$ and nilpotency class of $n-2$ where $n\ge 7$ then $p\le|Z(G)|\le p^2$ and $p^{n-3}\le |G'|\le p^{n-2}$.

I am not sure how these follow, I tried but couldn't succeed. I know from this post that nilpotency class of $G'$ is at most $n-3$ but I can not use it to get the required bound. I am really sorry if I am missing something easy.
If anyone can help me I will be really grateful.
Thanks
Answer: You have a finite $p$-group $G$ of order $p^{n}$ and nilpotency class $c=n-2$, with $n\geq 7$. You are seeking to show four things, labelled 1 to 4 below:
$$p \leq^{(1)} |Z(G)| \leq^{(2)} p^{2} $$
$$ p^{n-3} \leq^{(3)} |G^{\prime}| \leq^{(4)} p^{n-2} $$
(1) For a finite $p$-group we must have $p \leq |Z(G)|$. One of the most important facts about finite $p$-groups is that their center is non trivial. As this is a standard result in basic courses I will not prove it here. For a reference see here.
(2) We wish to show that $|Z(G)| \leq p^{2}$. Consider the upper central series of $G$:
$$1=Z_{0}(G)<Z_{1}(G)<\dots<Z_{c-1}(G)<Z_{c}(G)=G$$
The series consists of $c+1$ terms and $c$ factors. It is clear that each factor has order at least $p$, or else we would have a redundant term.
I claim that the last factor, $\frac{G}{Z_{c-1}(G)}$, must have order at least $p^{2}$. Suppose for contradiction that this last factor has order $p$. We work modulo $Z_{c-2}(G)$, and observe that $\frac{Z_{c-1}(G)}{Z_{c-2}(G)}$ is the center of $\frac{G}{Z_{c-2}(G)}$.
Notice that $\frac{G/Z_{c-2}(G)}{ Z_{c-1}(G)/Z_{c-2}(G)} \cong \frac{G}{Z_{c-1}(G)} $ by the isomorphism theorems, and that by our assumption this is of order $p$, hence the quotient is cyclic. Thus we are taking a quotient by the center and end up with something cyclic, and so by a well known result $G/Z_{c-2}(G)$ must be abelian. Hence $[G,G]\leq Z_{c-2}(G)$. However this now means if we consider the upper central series, the term $Z_{c-1}(G)$ is redundant, and so we can obtain a central chain of shorter length, contradicting the assumption that the class is $c$. Thus we see the order of the last factor must be at least $p^{2}$.
Now if $|G|=p^{n}$ the product of all the factors must equal $n$. Explicitly $p^{n}=|G|=|\frac{Z_{1}(G)}{1}||\frac{Z_{2}(G)}{Z_{1}(G)}|\dots|\frac{G}{Z_{c-1}(G)}|$.
There are $c=n-2$ factors and each factor has order at least $p$ with the final factor $\frac{G}{Z_{c-1}(G)}$ at least $p^{2}$. Now by considering the order of the first factor, it is clear that $|Z_{1}(G)| \leq p^{2}$ or else the order of the group would be too large.
(3) Now we will show $p^{n-3} \leq |G^{\prime}|$. Consider the lower central series of $G$.
$$G>\gamma_{2}(G)> \dots > \gamma_{c}(G)>1$$ where $\gamma_{2}(G)=[G,G]$.
Each of the $c-1$ factors in the product below must have order at least $p$ and so $|[G,G]|=|\gamma_{2}(G)|=|\frac{\gamma_{2}(G)}{\gamma_{3}(G)}|\dots |\frac{\gamma_{c}(G)}{\gamma_{c+1}(G)}| \geq p^{c-1}=p^{n-3} $.
(4) Finally we show $|G^{\prime}|\leq p^{n-2}$. Consider the upper central series as in (2). We have that $[G,G]\leq Z_{c-1}(G)$ (this is clear from the definition of the upper central series). Given what we have shown in (2), that the factor $\frac{G}{Z_{c-1}(G)}$ must have order at least $p^{2}$, it follows that the order of $Z_{c-1}(G)$ is at most $p^{n-2}$. Hence $|G^{\prime}| \leq |Z_{c-1}(G)| \leq p^{n-2}$.
Comment: Thanks for your answer. Such a detailed answer is so helpful. The claim was not clear to me form the article, I understand now. Thanks. It is also nice to see (from your profile, sorry!) that you are interested in GAP and p-groups :) I also like these topics. Thanks a lot again.


How to use curtime() to check in column with now() structure? SQL

Question: In my DB when a new user register I use now() for the column date_added (I need the exact time of registration). Also I store the user ip in column ip
Now I need to check in SQL if there is already registration from this ip from today
BUT
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer
    WHERE ip = '" . $this->db->escape($ip) . "'
    AND date_added = CURDATE()");

    return $query->row;

Does not work because I use now() for date_added and now() is not = to curdate()
Any ideas how to do the trick?
Answer: Use DATE()
... AND date(date_added) = CURDATE()

Comment: @PetarStoyanov - Arg.  Please be aware that *(afaik)* this will prevent the use of indexes so fullfil the query, resulting in a full scan.  Why not simply use `date_added >= CURDATE()`?  Your description means that you won't have any records in the future, and even if you do, just add `AND date_added < CURDATE()+1`.


Insert com acentos no Oracle

Question: Quando eu faço um INSERT por exemplo:
INSERT INTO TESTE (NOME) VALUES ('INSCRIÇÃO ESTADUAL');

Está salvando na tabela dessa forma:

INSCRI����O ESTADUAL

E na tela exibe "INSCRIÃÃO ESTADUAL".

Estou utilizando o Oracle SQL Developer, quando eu entro na tabela e altero na mão, ai sim salva corretamente:

INSCRI��O ESTADUAL

E na tela exibe corretamente "INSCRIÇÃO ESTADUAL".

Configuração do NLS

Executando SELECT PARAMETER, VALUE FROM NLS_DATABASE_PARAMETERS

Até olhei a configuração do meu NLS e aparentemente está ok, existe alguma forma de alterar o encoding na hora do INSERT?
Comment: Qual o output de "SELECT PARAMETER, VALUE FROM NLS_DATABASE_PARAMETERS"?
Comment: @bruno Nesse caso o charset está `NLS_CHARACTERSET US7ASCII`
Comment: @bruno Alterei a pergunta com todos valores
Comment: A resposta em baixo do Paulo Roberto ajudou?
Comment: @bruno Não, continua inserindo da forma incorreta, até dei um `echo $NLS_LANG`, mostra que eu alterei só que não influência em nada no meu Oracle
Comment: Podes confirmar se eu percebi: No Oracle SQL Developer, quando executas a instrução de INSERT os caracteres não estão a ser guardados correctamente, mas quando editas a tabela eles são guardados com os acentos?
Comment: Exatamente @bruno
Comment: Você está inserindo por onde? É um sistema? Se for uma página, não pode ser o encoding da mesma? No HTML?
Answer: Talvez, isso resolva o seu problema, se não resolver cocloque o erro ai que vams buscar juntos a solução.
Crie uma variável de ambiente chamada NLS_LANG, com o valor .WE8ISO8859P1. Conforme figura abaixo.

Se não resolver leia este artigo: http://www.fabioprado.net/2012/11/configurando-national-language-support.html
Comment: Aqui não funcionou, eu uso `Ubuntu` e até dei um `export` na variável, defini no "profile", encerrei a sessão e testei novamente... não adiantou :/
Answer: Use variáveis de ambiente NLS_LANG para configurar corretamente, pois ele deve estar entrando como ASCII (7 bits), use export para Linux e set para Windows.
Se o dado de entrada estiver codificado em ambiente Windows:
export/set NLS_LANG='AMERICAN_AMERICA.WE8MSWIN1252'

Em ISO-8859-P1 (Unix):
`export/set NLS_LANG='AMERICAN_AMERICA.WE8ISO8859P1'`

Em UTF-8:
export/set NLS_LANG='AMERICAN_AMERICA.AL32UTF8'

Comment: Lucas eu fiz isso, foi a mesma coisa que o Paulo Roberto sugeriu, eu até adicionei no `~profile` além de fazer o export na hora também e nada. Dentro do Sql Developer não pega.
Comment: Podes fazer um teste no sql*plus, só para confirmar se é problema do sql developer, ou se é problema das variáveis de ambiente do linux.
Answer: Tive um problema parecido, quando ia utilizar um client oracle via docker, os registros inseridos que continha acentos ficavam todos bagunçados, só consegui resolver exportando a varivel NLS_LANG=AMERICAN_AMERICA.UTF8

Insert com acentos no Oracle


Use view from other MVC project

Question: I have a few MVC3 projects that uses the same partial views. These views contain parts of forms that i can easily reuse in other MVC projects. is there a way to centralize Views. Like, in another project perhaps? So i can add the assembly of the project and easily call the views i need?
Otherwise i have to copy the reusable views folder every time i start a new project. And when i make a change to one of those views, then i have to change it in all the other projects too. Would be better if i could put it in one place and reference to it somehow.
Is this possible?
Comment: possible duplicate of [How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?](http://stackoverflow.com/questions/4823579/how-can-i-make-asp-net-mvc-3-use-views-aspx-ascx-files-from-an-external-assem)
Answer: The easiest solution is to simply map a shared virtual folder in your views folder, using IIS's virtual folder feature.  That way all apps that use the same views will actually point to the same physical folder.
You may have some challenges with deployment, and you could make the shared folders part of their own project.  But you will need to deal with that both on the local dev machine and the server.

Use view from other MVC project


How to grant secure access to an untrusted developer to an exisiting virtual host?

Question: Our security policy does not permit ftpd on our servers. Our trusted developers use sftp to access our webservers and they have full access to the server. How do we grant limited access to a single untrusted developer for an existing virtual host. Ive configured rssh to only allow sftp to our untrusted developer, but we dont want him browsing around our other sites. I've investigated chroot, but it seems overly complex and more for restricting access to their home folders. I want to limit access to /srv/www/vhostx/ and below.
Whats the best solution?
Comment: Your post mentions ftps but the tag says sftp. Which is it? Huge difference. sftp would let you use the chroot functionality in OpenSSH's sshd.
Comment: Yes, sorry it was a mistake, I meant sftp. I have edited it.
Answer: Use Match, ForceCommand and ChrootDirectory in sshd_config to restrict the user foo to a particular directory:

Match user foo
ForceCommand internal-sftp
ChrootDirectory /srv/www/vhostx/
Comment: This is the best solution except on Centos 5.x it requires manually upgrading openssh to version 5+. I built openssh 5.2 source rpm's and its all working now!
Answer: Use sftp, chroot to his home dir, set his home dir to /srv/www/vhostx/. If that's not possible, make a new account for him to use when uploading which does have those settings.


OCMockito - Verify order of method invocations

Question: As far as I can see, there is no way to verify the order of method invocations on a mock.
Or am I missing something?
- (void)testResetCameraState_resetsCameraView
{
   // Arrange
   [given([_cameraManagerMock previewLayer]) willReturn:_testLayer];

   // Act
   [_cameraInteractor resetCameraState];

   // Assert
   [verifyCount(_cameraViewMock, times(1)) resetPreview];
   [verifyCount(_cameraViewMock, times(1)) setPreviewLayer:_testLayer];
}

In this case you cannot verify, that the setPreviewLayer: is called after resetPreview.
Answer: I think I found a solution.
It's based on the givenVoid method added in this pull request:
https://github.com/jonreid/OCMockito/pull/93
Sadly it is not merged yet, so you need to download and build this version by yourself:
https://github.com/lysannschlegel/OCMockito/tree/given_void
With the new method you can verify the order of method calls in the following way:
- (void)testResetCameraState_resetsCameraView
{
    // Arrange
    [given([_cameraManagerMock previewLayer]) willReturn:_testLayer];
    [givenVoid([self->_cameraViewMock resetPreview]) willDo:^id (NSInvocation *invocation)
     {
         [(MKTBaseMockObject*)self->_cameraViewMock reset];
         return nil;
     }];

    // Act
    [_cameraInteractor resetCameraState];

    // Assert
    [verifyCount(_cameraViewMock, never()) resetPreview];
    [verifyCount(_cameraViewMock, times(1)) setPreviewLayer:_testLayer];
}

This will reset the mock after the first call of resetPreview.
So we can verify stuff after that call:

resetPreview is never called after the first call.
setPreviewLayer is called after resetPreview.

The reset call also resets the givenVoid() willDo: so a second reset call wouldn't reset the mock again.
Hope this helps, happy coding :D