probability or statistics – Unexpected PDF in `FirstPassageTimeDistribution`

I am new to Markov Processes, and while learning the discrete Markov chain with the following matrix $$P=begin{bmatrix}frac{1}{3} & frac{2}{3} & 0 & 0 \ frac{1}{2} & frac{1}{2} & 0 & 0 \
frac{1}{4} & 0 & frac{1}{4} & frac{1}{2} \0 & 0 & 0 & 1end{bmatrix},$$

I was told that $f_{34}(n)=left(frac14right)^{n-1}frac12$, where $f_{ij}(n)$ denotes the probability that starting in state $i$, we visit $j$ for the first time at time $n$. I can also verify this by hand.

I’ve tried the following input in Mathematica:

p = {{1/3, 2/3, 0, 0}, {1/2, 1/2, 0, 0}, {1/4, 0, 1/4, 1/2}, {0, 0, 0, 1}};
P = DiscreteMarkovProcess(3, p);
f34 = FirstPassageTimeDistribution(P, 4);
PDF(f34, n)

But the result is $$left{begin{array}{ll} 3 times 4^{-n} & n>0 \0 & text { True }end{array}right.$$

I’m confused since $f_{34}(1)=p_{34}=frac12$, how can it be $frac34$ as given? I’m using the version 12.1.1.0, could anyone give me a hint where I went wrong? Thanks!

functions – Unexpected behaviour with Coefficient

If I run

expr = (CF G(0, zb))/(1 - zb) + (CF zb^2 G(0, zb))/(1 - zb) + (2 CF G(1, zb))/(1 - zb) + (2 CF zb^2 G(1, zb))/(1 - zb);
Coefficient(expr, zb, -1) 

in Mathematica 12.1, it returns

-((CF G(0, zb))/(-1 + zb)) - (2 CF G(1, zb))/(-1 + zb)

Shouldn’t it return 0 since there are no terms in the form 1/zb in expr ?

postgresql – ODBC Calling Fill – Unexpected closed connection after 2 hours

Using PostgreSQL 12.3 (Ubuntu 12.3-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
I use driver PostgresSQL Unicode(x64) version 13.00.00.00

I have a query that is executed through an ODBC connection in a Powershell 5.1 script. I use the Fill() method to retreive about 3500 records daily. When the script works, it takes 2-5 minutes to execute and retrieve data when it works.
Problem is that the script “fails” half of the time approx. When this occurs, the Powershell script does stop only after 2h and 30 seconds.

We double checked the postgres logs and when this occurs, we see that the query successfully completed within 6 minutes always. I don’t know what to look for. any Idea?

Below is the error got:

Executed as user: NT ServiceSQLSERVERAGENT. A job step received an error at line 94 in a PowerShell script. The corresponding line is ‘(New-Object system.Data.odbc.odbcDataAdapter($cmd)).fill($ds) | out-null ‘. Correct the script and reschedule the job. The error information returned by PowerShell is: ‘Exception calling “Fill” with “1” argument(s): “The connection has been disabled.” ‘. Process Exit Code -1.

Not too familiar with postgreSQL.

Thanks!

Form APi Could not parse property path Unexpected token

Using

  • Drupal 9.1.4
  • symfony/property-access I think is on 5.2.0 (that’s the last version mentioned in the changelog)

I have a custom built form with some date and number fields, for example:

$form('calculator')('chargeable_consideration') = (
  '#type' => 'number',
  '#min' => 0,
  '#step' => 0.01,
  '#required' => TRUE,
  '#size' => 13,
  '#attributes' => (
    'placeholder' => '£0.00',
  ),
  '#title' => $this->t('description text (£) <button class="tooltip-anchor" title="pop up text">?</button>'),
  '#prefix' => '<div class="form-group">',
  '#suffix' => '</div>',
);

I have validation checking the dates are within a range, but nothing to check the numbers.

if I use the numbers

  • 10000.85
  • 123456789.70
  • 1234567890

the form works as expected.

If I use the numbers

I get the following error

SymfonyComponentPropertyAccessExceptionInvalidPropertyPathException: Could not parse property path "calculator)(chargeable_consideration". Unexpected token "(" at position 11. in SymfonyComponentPropertyAccessPropertyPath->__construct() (line 111 of vendorsymfonyproperty-accessPropertyPath.php).
SymfonyComponentPropertyAccessPropertyAccessor->getPropertyPath('calculator)(chargeable_consideration') (Line: 120)
SymfonyComponentPropertyAccessPropertyAccessor->getValue(Array, 'calculator)(chargeable_consideration') (Line: 406)
Drupalcustom_formFormCustomForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)

How do I prevent it from throwing this exception?

unity – Unexpected Result On Coroutines Called From Another Script

So I performed tests on calling coroutines from another script. I want to understand why the results aren’t the expected behavior in one of the test case, and unfortunately the one that I needed to use (as it is more dynamic).

Tests:

// TEST 1: Running coroutines from passed IEnumerator
m_Tester.StartCoroutine(1);

// TEST 2: Running coroutines in this script through a delegate
m_TesterByFunc.StartCoroutineByFunc(1);
        
// TEST 3: Running coroutines by starting them publicly via this script 
m_TesterByCasting.StartCoroutineByCasting(1);

The idea is I’d like to call coroutines from another script – in this case, from a plain class. And I’m expecting that my coroutines would run normally. However, the problem is when passing IEnumerator to the Tester class, along with the owning Monobehavior object, then starting the coroutines from it (Tester class) only worked once. Calling StartCoroutine from CoroutineTest via a delegate function or publicly worked as intended.

I’m not sure if anyone has encountered this but I’d love to know why I’m getting the unexpected result particularly for Test #1.

  • Is there a problem with passing IEnumerator and caching them in the class and the reason why it only works once? Is it not passed by reference?

Please see the test scripts below.

Script 1:

public class Tester
{
    public delegate void Function();

    private MonoBehaviour m_Owner;
    private Function m_F1;
    private Function m_F2;
    private IEnumerator m_One;
    private IEnumerator m_Two;

    public Tester (MonoBehaviour owner)
    {
        m_Owner = owner;
    }

    public Tester(MonoBehaviour owner, IEnumerator one, IEnumerator two)
    {
        m_Owner = owner;
        m_One = one;
        m_Two = two;
    }

    public Tester(MonoBehaviour owner, Function f1, Function f2)
    {
        m_Owner = owner;
        m_F1 = f1;
        m_F2 = f2;
    }    

    public void StartCoroutine(int index)
    {
        if (index == 0)
        {
            m_Owner.StopCoroutine(m_Two);
            m_Owner.StartCoroutine(m_One);
        }
        
        if (index == 1)
        {
            m_Owner.StopCoroutine(m_One);
            m_Owner.StartCoroutine(m_Two);
        }
    }

    public void StartCoroutineByFunc(int index)
    {
        if (index == 0)
        {
            m_F1();
        }

        if (index == 1)
        {
            m_F2();
        }
    }

    public void StartCoroutineByCasting(int index)
    {
        var test = (m_Owner as CoroutineTest);

        if (index == 0)
        {
            test.StopCoroutine(test._TestTwoByCasting());
            test.StartCoroutine(test._TestOneByCasting());
        }

        if (index == 1)
        {
            test.StopCoroutine(test._TestOneByCasting());
            test.StartCoroutine(test._TestTwoByCasting());
        }
    }
}

Script 2: Attach to a game object in the scene

public class CoroutineTest : MonoBehaviour
{
    private Tester m_Tester;
    private Tester m_TesterByFunc;
    private Tester m_TesterByCasting;

    private void Awake()
    {
        m_Tester = new Tester(this, _TestOne(), _TestTwo());
        m_TesterByFunc = new Tester(this, TestOneByFunc, TestTwoByFunc);
        m_TesterByCasting = new Tester(this);
    }

    private void OnEnable()
    {
        // TEST 1: Running coroutines from passed IEnumerator
        m_Tester.StartCoroutine(1);

        // TEST 2: Running coroutines in this script through a delegate
        m_TesterByFunc.StartCoroutineByFunc(1);
        
        // TEST 3: Running coroutines by starting them publicly via this script 
        m_TesterByCasting.StartCoroutineByCasting(1);        
    }

    public IEnumerator _TestOne()
    {
        Debug.Log("Test one");

        yield return new WaitForSeconds(3f);

        m_Tester.StartCoroutine(1);
    }

    public IEnumerator _TestTwo()
    {
        Debug.Log("Test two");

        yield return new WaitForSeconds(3f);

        m_Tester.StartCoroutine(0);
    }

    private void TestOneByFunc()
    {
        StopCoroutine(_TestTwoByFunc());
        StartCoroutine(_TestOneByFunc());
    }

    private void TestTwoByFunc()
    {
        StopCoroutine(_TestOneByFunc());
        StartCoroutine(_TestTwoByFunc());
    }

    private IEnumerator _TestOneByFunc()
    {
        Debug.Log("Test one by func");

        yield return new WaitForSeconds(3f);

        m_TesterByFunc.StartCoroutineByFunc(1);
    }

    private IEnumerator _TestTwoByFunc()
    {
        Debug.Log("Test two by func");

        yield return new WaitForSeconds(3f);

        m_TesterByFunc.StartCoroutineByFunc(0);
    }

    public IEnumerator _TestOneByCasting()
    {
        Debug.Log("Test one by casting");

        yield return new WaitForSeconds(3f);

        m_TesterByCasting.StartCoroutineByCasting(1);
    }

    public IEnumerator _TestTwoByCasting()
    {
        Debug.Log("Test two by casting");

        yield return new WaitForSeconds(3f);

        m_TesterByCasting.StartCoroutineByCasting(0);
    }
}

Thanks!

Unexpected HY001: Memory allocation error after MySQL upgrade

Earlier today I upgraded a db.t3.large MySQL instance on AWS from v8.0.13 to 8.0.20. I’ve seen a handful of cases where I’m seeing the error SQLSTATE(HY001): Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size. I don’t expect such an error because the config or instance type didn’t change. An example of where I’m seeing this is on the following query:

SELECT * FROM `messages`
WHERE
    EXISTS (
        SELECT * FROM `updates`
        WHERE
            `messages`.`update_id` = `updates`.`id`
            AND `game_id` = 18
    )
    AND `messages`.`deleted_at` IS NULL
ORDER BY `id` DESC
LIMIT 6

In this query, all columns used in the order and where clauses are either foreign or primary keys with messages.deleted_at being the only exception.

In the meantime I’m going to adjust this setting in my prod environment to increase the size of the sort_buffer_size, but this change is not recommend according to a lot of stuff I’m reading so I hope it’ll temporarily resolve the issue.

plugins – JSON.parse: unexpected character at line 1 column 1 when sending payment request

I’m coding a payment gateway plugin for woocommerce but I’m getting stuck on this error when I send a payment auth request to the offsite company that processes the payments. Once the auth request is sent off, I’m supposed to get a response token, that will be appended to a url which will be the payment page the customer will see.

$hostedPageRequest = (
            'Request' => (
                'CardHolderResponseURL' => "https://offapp1/FAC.MerchantIntegration.WebTools/Home/HttpRequestParser",
                'RecurringDetails' => null,
                'ThreeDSecureDetails' => null,
                'TransactionDetails' => (
                    'AcquireId' => $acquirerId,
                    'Amount' => $amountFormatted,
                    'Currency' => $currency,
                    'CurrencyExponent' => 2,
                    'IPAddress' => '',
                    'MerchantId' => $merchantId,
                    'OrderNumber' => $orderNumber,
                    'Signature' => $signature,
                    'SignatureMethod' => 'SHA1',
                    'TransactionCode' => 8,
                    'CustomData' => '',
                ),
            ),
        );

        $result = $client->HostedPageAuthorize($hostedPageRequest);
        
        $token = $result->HostedPageAuthorizeResult->SingleUseToken;

        $paymentPageUrl = "https://$domain/MerchantPages/$pageset/$pagename/";

        $redirectUrl = $paymentPageUrl.$token;

I get the json error on the “$result = $client->HostedPageAuthorize($hostedPageRequest)” line of the code.

What exactly am I doing wrong? I’m overall new to PHP and backend coding in general.

Thanks

ERROR IN in my SPFX WebPart : Module parse failed: Unexpected token You may need an additional loader to handle the result of these loaders

I have created an SPFx project with reactJS. I am using .jsx extension – functional components.

Now, the spfx webpart is already working fine, but I saw a material kit that I want to reuse its components.

When I referenced the components, I am presented with this error

(SPLoaderError.loadComponentError):
***Failed to load component (WebPart). Original error: ***Failed to load entry point from component WebPart). Original error: Module parse failed: Unexpected token (30:4)
File was processed with these loaders:
./node_modules/source-map-loader/index.js
You may need an additional loader to handle the result of these loaders.

enter image description here

It seems that I cannot use the “footer” tag?

enter image description here

AddTo operation to random element of a list yields unexpected results

I have a list of numbers. I want to randomly select one of those, with a probability proportional to its value, and increment it by one.

I tried this simple one-liner

my_list = {1,1,1}
my_list((RandomSample(my_list->Range(Length(my_list)))) += 1

and it works just fine as long as the elements of my_list are all identical. However, when my_list contains values that are not all identical, sometimes it fails spectacularly, e.g.:

SeedRandom(1)
my_list = {1,2,3}
my_list((RandomSample(my_list->Range(Length(my_list)))) += 1
{4,2,3}

My guess is that for some reason here RandomSample is called twice, once for deciding which number from my list is incremented by 1 and then another time to decide where to store the result of the operation. So in the above example first the number 3 is incremented by 1, and then the result is stored in position 1.

If this is the case, is this an expected behaviour? If not, can you explain it?

P.s. There is of course a trivial workaround, i.e. to store the result of RandomSample in a temporary variable and use that to index my_list. But here I would like to understand what is happening exactly in my one-liner.

P.p.s: to put things in perspective, the same thing e.g. in python would just work, that’s why I am particularly puzzled:

import numpy as np

my_list = np.array((1,2,3))
my_list(np.random.choice((0,1,2), p=my_list/my_list.sum())) += 1