machine learning – Pseudo-dimesnon of a subset of affine functions

Let’s say there are two sets of affine functions.

  1. $mathcal{A} = {ax +b | a,b in mathbb{R}}$
  2. $mathcal{H} = {2x + 1, x, 3x + 4, 4x}$

I know that the $Pdim(mathcal{A}) = 2$. From my understanding the $Pdim(mathcal{H})$ is also equal to 2 as I can find ${x_1, x_2}$ and $z_1, z_2$ such that for all subsets $T subseteq {x_1, x_2}$, there is a function $f in mathcal{H}$ such that $forall x in T, f(x) geq z_1$ and $forall x notin T f(x) < z_1$.

Is my intuition correct?

functions – Reducing a fraction containing numbers in numerical form

I am looking for a function that would transform a fraction of the form:

$$frac{1.0times 10^{-10}}{1.0times 10^{-11}+1.0times 10^{-12},x}$$

into this:
$$frac{1.0}{1.0times 10^{-1}+1.0times 10^{-2},x}$$

or this:

I’ve tried Simplify and FullSimplify but they don’t work this way.

Any help will be appreciated.

functions – Need to put a script above

I need to put this script above the tag in the header.php.

window.Futy = { key: ‘0000000000’ };
(function (e, t) {
var n = e.createElement(t);
n.async = true;
n.src = ‘’;
var r = e.getElementsByTagName(t)(0);
r.parentNode.insertBefore(n, r);
})(document, ‘script’);

But with the new header.php and hooks and function.php I don’t know how to do this.
I’m not a developer. So please tell me in a easy way as possible

functions – Changing the HTML of notices in WooCommerce

I’m creating a WooCommerce theme from scratch, and I’d really like to change the HTML that wraps the default WooCommerce messages on the Cart and Checkout pages.

I am specifically talking about the default messages that appear in this element, when the cart is updated – or items are removed:

<div class="woocommerce-message" role="alert">
        Your cart has been updated / Product was removed. Undo? 

I have tried several things;

  1. I am overriding the default error.php, success.php and notice.php templates in the templates/notices folder. These, I concluded, were seemingly only used for some of these notifications. My errors use the error template just fine, for example.

  2. I tracked, what I thought was the culprit, down to the function woocommerce_output_all_notices in the wc-template-functions.php file. I was almost sure that this was it, since it was the only function that I could find, being called inside the wrapping container (The <div class="woocommerce-notices-wrapper"> element).

The function looks like this:

function woocommerce_output_all_notices() {
    echo '<div class="woocommerce-notices-wrapper">';
    echo '</div>';

It would be logical to think, that the markup is then coming from the wc_print_notices() function.

However, when I look at this function in wc-notice-functions.php… It uses the templates that I mentioned in #1.. ?

What am I doing wrong here? Does anyone have experience with properly altering the markup of these message?

google sheets – Trying to run two functions onEdit

I have found two scripts that work independently, but fail when combined. I get this error message (ReferenceError: myfunction2 is not defined
onEdit @ I want one field to populate the date time a record was created and another field to populate the date and time of the last edit, basically to track how long it took to close the status on that record. Obviously, I am new to this, so please use lingo I can understand 🙂 Here is my code:

function onEdit(e) {
var SHEET_NAME = ‘Sheet1’;
var DATETIME_HEADER = ‘Call Time’;

function myfunction1(e) {

function getDatetimeCol(){
var headers = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME).getDataRange().getValues().shift();
var colindex = headers.indexOf(DATETIME_HEADER);
return colindex+1;

var ss = SpreadsheetApp.getActiveSheet();
var cell = ss.getActiveCell();
var datecell = ss.getRange(cell.getRowIndex(), getDatetimeCol());
if (ss.getName() == SHEET_NAME && cell.getColumn() == 1 && !cell.isBlank() && datecell.isBlank()) {
datecell.setValue(new Date()).setNumberFormat(“MM/dd/yyyy hh:mm:ss A/P”);

function myfunction2(e) {

var range = e.range;
var spreadSheet = e.source;
var sheetName = spreadSheet.getActiveSheet().getName();
var row = range.getRow();

if(sheetName == ‘Sheet1’)
var new_date = new Date();
spreadSheet.getActiveSheet().getRange(row,11).setValue(new_date).setNumberFormat(“MM/dd/yyyy hh:mm:ss A/P”);



domain name system – How to configure Firewall Rules and DNS settings on GCP with VPC Service Controls when using Cloud Composer and Cloud Functions in the same project?

We have troubles with the configuration of two GCP components (the GCP Cloud Composer, the GCP Functions) under VPC Service Controls for a single project. We can configure them separately with VPC Service Controls, but as soon as we add the second component we experience troubles.

Once we have configured the Firewall rules and DNS settings for the Cloud Function, the Composer starts to fail.
The Composer monitoring tool (for webserver, SQL server, etc.) shows that the composer is unhealthy.

What are we doing wrong?

The docs we’ve used:

For the Composer we use these settings:
3 node
standard machine type
image version: composer-1.16.3-airflow-1.10.15
python: v3
private IP Composer

The APIs what we have enabled for VPC Service Controls:
Restricted Services:
Google Cloud Dataproc API
Cloud Functions API
Google Cloud Pub/Sub API
Google Cloud Storage API
Google Compute Engine API
Google Kubernetes Engine API
Google Container Registry API
Cloud Monitoring API
Cloud Composer API
Artifact Registry API

The FireWall settings (based on the documentation):

Name Type Targets Filters Protocols / Ports Action Priority
composer-egress-gke-cluster-all-port Egress Apply to all IP ranges: tcp, udp Allow 1000
composer-egress-healthcheck Egress Apply to all IP ranges:, tcp:80,443 Allow 1000
composer-egress-port53 Egress Apply to all IP ranges: tcp:53, udp:53 Allow 1000
composer-egress-webserver Egress Apply to all IP ranges: tcp:3306,3307 Allow 1000
restricted-google-apis Egress Apply to all IP ranges: tcp:443 Allow 1000
composer-deny-all Egress Apply to all IP ranges: all Deny 2000
composer-ingress-helthcheck Ingress Apply to all IP ranges:, tcp:80,443 Allow 1000
ingress-iap Ingress Apply to all IP ranges: tcp Allow 1000
gke-europe-west1-composer-dns-xxx-xxx-all Ingress gke-europe-west1-composer-dns-xxx-xxx-node IP ranges: tcp;udp;esp;ah;sctp;icmp Allow 1000
gke-europe-west1-composer-dns-xxx-xxx-master Ingress gke-europe-west1-composer-dns-xxx-xxx-node IP ranges: tcp:10250,443 Allow 1000
gke-europe-west1-composer-dns-xxx-xxx-vms Ingress gke-europe-west1-composer-dns-xxx-xxx-node IP ranges: tcp:1-65535;udp:1-65535;icmp Allow 1000

The DNS settings (based on the documentation):

DNS name:
Type: Private

DNS name Type TTl(Seconds) Data
* CNAME 300 SOA 21600 1 21600 3600 259200 300 NS 21600

DNS name:
Type: Private

DNS name Type TTl(Seconds) Data
* A 300,,, NS 21600 1 21600 3600 259200 300 SOA 21600

DNS name:
Type: Private

DNS name Type TTl(Seconds) Data
* CNAME 300 SOA 21600 1 21600 3600 259200 300 NS 21600 A 300,,,

DNS name:
Type: Private

DNS name Type TTl(Seconds) Data
* CNAME 300 SOA 21600 1 21600 3600 259200 300 NS 21600 A 300,,,

Thank you for any idea or help what you can give.

functions – How to save custom made object in an array in a post meta field

I’ve made two custom classes:

I’m making a quite custom calculation of a bunch of things, that I would like to save in an array in a post_meta field.

This is how I save it

$obj1 = new FooBar();
$obj2 = new BarSchizzle();
$obj3 = new FooBar();

$arr = (
  'a_key' => $obj1,
  'another_key' => $obj2,
  'a_third_key' => $obj3,

update_post_meta( $post_ID, 'my_custom_field', $arr );

// I also tried this, with same result
// update_post_meta( $post_ID, 'my_custom_field', serialize( $arr ) );

This is how I retrieve the array

$initial_arr = get_post_meta( $post_ID, 'my_custom_field', true );
$arr = unserialize( $initial_arr ); // And this is where the error occurs

I’m getting the error: unserialize() (function.unserialize): Error at offset ... (you can read more about it here).

My theory is, that WordPress hasn’t gotten to loading (requiring) my custom classes, when it get’s (and unserializes).

I’ve required the classes by simply slapping them into the functions.php-file, in the top, like this:

require_once( __DIR__ . '/classes/FooBar.php' );
require_once( __DIR__ . '/classes/BarSchizzle.php' );

… Not inside any hook or anything. It felt a bit sloppy/bad, but it has been working perfectly up until now.

So this leaves me with two questions:

  • Do I need to put my require of my custom classes inside a hook, like init or something?
  • Are there another explanation why WordPress stumbles when it tries to unserialize that $arr, containing my custom objects?

equation solving – Finding multiple roots of three variables (with three functions)

I’m trying to find all the possible roots of three functions below (v1=f1(v1,v2,v3), v2=f2(v1,v2,v3) and v3=f3(v1,v2,v3)) with respect to a change in parameter l

(Beta) = 7.5; d = 3.85; c = 15.4;    
f1(v1_, v2_, v3_, l_) := (Beta)/(
      1 + c/d Exp(-(((v1 - (v2 + v3)/2) l)/d))/(
        1/(v1 - (v2 + v3)/2) (1 - Exp(-(((v1 - (v2 + v3)/2) l)/d))) + 
         1/(v2 - (v1 + v3)/2) (1 - Exp(-(((v2 - (v1 + v3)/2) l)/d))) + 
         1/(v3 - (v2 + v1)/2) (1 - Exp(-(((v3 - (v2 + v1)/2) l)/d)))));
    f2(v1_, v2_, v3_, l_) := (Beta)/(
      1 + c/d Exp(-(((v2 - (v1 + v3)/2) l)/d))/(
        1/(v1 - (v2 + v3)/2) (1 - Exp(-(((v1 - (v2 + v3)/2) l)/d))) + 
         1/(v2 - (v1 + v3)/2) (1 - Exp(-(((v2 - (v1 + v3)/2) l)/d))) + 
         1/(v3 - (v2 + v1)/2) (1 - Exp(-(((v3 - (v2 + v1)/2) l)/d)))));
    f3(v1_, v2_, v3_, l_) := (Beta)/(
      1 + c/d Exp(-(((v3 - (v1 + v2)/2) l)/d))/(
        1/(v1 - (v2 + v3)/2) (1 - Exp(-(((v1 - (v2 + v3)/2) l)/d))) + 
         1/(v2 - (v1 + v3)/2) (1 - Exp(-(((v2 - (v1 + v3)/2) l)/d))) + 
         1/(v3 - (v2 + v1)/2) (1 - Exp(-(((v3 - (v2 + v1)/2) l)/d)))));

I’m trying to use FindRoot and eliminate duplicates, however I seem to miss many of the roots.

this is my attempt

lList = Table(l, {l, 1.4, 3.7, .001}); v11List = 
 Table({}, {i, 1, Length(lList)});
v21List = Table({}, {i, 1, Length(lList)}); v31List = 
 Table({}, {i, 1, Length(lList)}); v12List = 
 Table({}, {i, 1, Length(lList)});
v22List = Table({}, {i, 1, Length(lList)}); v32List = 
 Table({}, {i, 1, Length(lList)});
v13List = Table({}, {i, 1, Length(lList)});
v23List = Table({}, {i, 1, Length(lList)}); v33List = 
 Table({}, {i, 1, Length(lList)});
list = Table({l, 
         N@Round(10000*{v1, v2, v3} /. 
             Quiet@FindRoot({v1 == f1(v1, v2, v3, (Beta), l), 
                v2 == f2(v1, v2, v3, (Beta), l), 
                v3 == f3(v1, v2, v3, (Beta), l)}, {v1, 20}, {v2, 
                v0}, {v3, 1}, AccuracyGoal -> Infinity, 
               PrecisionGoal -> 18))/10000)), 5), {v0, 1, 19, 
       1}))}, {l, 1.4, 3.7, .001});
For(i = 1, i < Length(list) + 1, i++, tmp1 = list((i))((2));
 If(Length(tmp1) == 1,
  v11List((i)) = {lList((i)), tmp1((1))((1))((1))}; 
  v21List((i)) = {lList((i)), tmp1((1))((1))((2))}; 
  v31List((i)) = {lList((i)), tmp1((1))((1))((3))}; 
  v12List((i)) = {lList((i)), tmp1((1))((1))((1))}; 
  v22List((i)) = {lList((i)), tmp1((1))((1))((2))}; 
  v32List((i)) = {lList((i)), tmp1((1))((1))((3))};);
 If(Length(tmp1) > 1,
  v11List((i)) = {lList((i)), tmp1((1))((1))((1))}; 
  v21List((i)) = {lList((i)), tmp1((1))((1))((2))}; 
  v31List((i)) = {lList((i)), tmp1((1))((1))((3))}; 
  v12List((i)) = {lList((i)), tmp1((2))((1))((1))}; 
  v22List((i)) = {lList((i)), tmp1((2))((1))((2))}; 
  v32List((i)) = {lList((i)), tmp1((2))((1))((3))};);)

As you can see in the result below, many of the curves have missing parts (meaning that not all the roots are found)

ListLinePlot({v11List, v21List, v31List, v12List, v22List, 
  v32List}, ImageSize -> 250, 
 PlotRange -> {{1.4, 3.7}, {0, (Beta) + 1}}, 
 PlotLegends -> {"v2", "v1", "v3"}, AxesLabel -> {"l", "v"}, 
 LabelStyle -> {FontSize -> 12}, 
 PlotStyle -> {Red, Blue, Green, Red, Blue, Green, Red, Blue, Green})

enter image description here

Can anyone please help and advice on how to properly find all the roots of v1 v2 v3 as a function of l?

java – Correct use of Serializable with lambda functions

I’m practicing saving and reading serializable objects when a friend told me serializable objects have no use in real life, that I’d better focus on JSON or XML to serialize my objects when I came across this situation:

I want to preload some FileFilters to use them in a JFileChooser dialog and I want these Filefilters to have more complicated behaviour than just file extension.

The code works fine but I’ve read there could be some security issues saving executable code and reading it later. Is it true? Can they be avoided?

I had to implement my own interface of Predicate due to the fact that Predicate is not Serializable.


public interface MyPredicate extends Serializable {
  boolean isValid(File file);

This is the class that defines how the filters are going to be set (It’s called List despite the fact that uses internally a Map just in case implementation changes).

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class FileFilterList implements Serializable {
  private Map<String, MyPredicate> filters;

  public FileFilterList() {
    this.filters = new HashMap<>();

  public FileFilterList addFilter(String string, MyPredicate predicate) {
    this.filters.put(string, predicate);
    return this;

  public Iterator<Map.Entry<String, MyPredicate>> getIterator() {
    return this.filters.entrySet().iterator();

In this little program I save a list of filters in a file


public class SaveFileFilter {
  public static void main(String() args) throws IOException {
    FileFilterList filterList = new FileFilterList();
            .addFilter("txt, Text files", f -> f.isDirectory() || f.getName().endsWith(".txt"))
            .addFilter("Big txt, Big txt files (>1Kb)", f -> f.isDirectory() || (f.getName().endsWith(".txt") || f.length() > 1024))
            .addFilter("Small txt, Small txt file (<=1Kb)", f -> f.isDirectory() || (f.getName().endsWith(".txt") || f.length() <= 1024));
    try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("filters.obj"))) {
    } catch (IOException ioe) {
      System.err.println("Sorry, there wa a problem saving filters");
      throw ioe;

And this would be the main program that get the preset file filter list:

import javax.swing.*;
import javax.swing.filechooser.FileFilter;

public class FileFilterUse {
  public static void main(String() args) throws IOException, ClassNotFoundException {
    JFileChooser fileChooser = new JFileChooser();
    try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("filters.obj"))) {
      FileFilterList filterList = (FileFilterList) ois.readObject();
              (entry) -> fileChooser.addChoosableFileFilter(new FileFilter() {
                public boolean accept(File f) {
                  return entry.getValue().isValid(f);

                public String getDescription() {
                  return entry.getKey();
    } catch (IOException ioe) {
      System.err.println("There was a problem reading filters file");
      throw ioe;
    } catch (ClassNotFoundException cnf) {
      System.err.println("File format is not correct");
      throw cnf;

Every java file has a package line.

I guess it is not possible to achive this serializing objects to JSON or XML, is it?

By the way, any comment about the code would be very appreciated.

Using external conditions with functions in bash

As a part of my bash script, I am dealing with the optimization of some function, which take input csv file(s) and process it via some AWK script. This is the function, which operates on input file(s):

rescore_data () {
# accepting $str file(s) given outside the function in bash
echo "DEBUG info: The following CSV file is being processed:" $str
str_name=$(basename ${str} .csv)
printf >&2 "Dataset for ${str_name} is being rescored...  "; sleep 0.1 
mkdir ${rescore}/${str_name}
# applying this AWK code on many directories, each of which contains target csv file(s)
while read -r d; do
awk -F ", *" '# SOME AWK CODE and save output inside the same directory (d)                
'  "${d}_"*/${str} > "${rescore}/${str_name}/"${d%%_*}".csv" 

And this is control flow how this function may be called inside of bash script according to two different conditions defined manually (1 – operating just with one file; 2 – loop over several filles from list and process each by the function):

# list of target CSV filles
strategies=('*str1.csv' '*str2.csv' '*str3a.csv' '*str3b.csv')
if (( "${MY_FILT_METHOD}" == 1 )); then
   # this is a target file present in each of the directories
   # run rescore_data function to process it
  elif (( "${MY_FILT_METHOD}" == 0 )); then 
   # in each dir there are several target filles, defined in the array list
   for str in ${strategies(@)}; do
   echo "GREAT NEWS: when you see this message, you code is wrong!"

May this workflow be modified to automatically define the variable $str inside the function according to the same variable provided in the control flow IF conditions part?