performance – Optimization of the code to calculate the scores of a set of Python models

I have a set of code that calculates how well a model fits the details of a user. It is a bit long, so I cut all the code that does its job well and I only included the neck of the bottle and the surrounding code. My goal here is speed!

A few notes on the variables:

Calculated at runtime (changes each user):

  • TopSecHead – channel list list – different sublist lengths
  • allSecScoreDicP1 – float list dict – always the same length
  • allSecScoreDicP2 – dict of the float list – always the same length
  • allSecReducerDicP1 – float list dict – always the same length
  • allSecReducerDicP2 – dict of the float list – always the same length

The last 4 above are all the same dimensions from each other

Calculated once and saved / loaded (does not change per user):

  • docSecSizesFull – float list list list – sublists do not have the same length

  • shortSecSizesFull – float list list – sublists do not have the same length

  • cutPointsFull – float list list list – sublists are not the same length

  • tmplNumFull – float list list list – sublists do not have the same length

  • AllDocSplitsFull – float list list – sublists do not have the same length

The above five are the same dimensions as each other.

for x in range(4,8,1):

    docSecSizes = docSecSizesFull(x-4)
    shortSecSizes = shortSecSizesFull(x-4)

    cutPoints = cutPointsFull(x-4)
    tmpltNum = tmplNumFull(x-4)

    layoutNums = 0

    numTemps = len(docSecSizes)
    tmpsplits = ()
    tmpsplits = (AllDocSplitsFull(x-4)(z) for z in range(numTemps))
    alltmplIds = (tmplNumFull(x-4)(z) for z in range(numTemps))

    for y in list(itertools.permutations(TopSecHead(x-4)(1:))):

        tmpHeadSec = ()
        tmpHeadSec.append('BasicInfo')

        headingIDs = ()
        headingIDs.append(str(0))

        for z in y:
            tmpHeadSec.append(z)          
            headingIDs.append(str(headingLookups.index(z)))

        SectionIDs = ','.join(headingIDs)

        tmpvals = ()


        tmpArray = ()
        for key in allSecScoreDicP1:
            tmpArray.append(allSecScoreDicP1(key))
        nparr = np.array(tmpArray)
        print(nparr.transpose())

        for z in range(numTemps):

            docScore = 0
            docScoreReducer = 1

            for q in range(len(shortSecSizes(z))):

                if q < cutPoints(z):
                    indexVal = shortSecSizes(z)(q)
                    docScore+= allSecScoreDicP1(tmpHeadSec(q))(indexVal)
                    docScoreReducer *= allSecReducerDicP1(tmpHeadSec(q))(indexVal)
                else:
                    indexVal = shortSecSizes(z)(q)
                    docScore+= allSecScoreDicP2(tmpHeadSec(q))(indexVal)
                    docScoreReducer *= allSecReducerDicP2(tmpHeadSec(q))(indexVal)
            docScore = docScore * docScoreReducer
            tmpvals.append(docScore)

        numTemplate = len(tmpvals)
        totaldocs += numTemplate
        sectionNum = (x) * numTemplate
        layoutNumIterable = (layoutNums) * numTemplate
        SectionIDsIterable = (SectionIDs) * numTemplate
        scoredTemplates.append(pd.DataFrame(list(zip(sectionNum,alltmplIds,layoutNumIterable,tmpvals,SectionIDsIterable,tmpsplits)),columns = ('#Sections','TemplateID','LayoutID','Score','SectionIDs','Splits')))
        layoutNums +=1


allScoredTemplates = pd.concat(scoredTemplates,ignore_index=True)

The problem code is this bit:

for z in range(numTemps):

    docScore = 0
    docScoreReducer = 1

    for q in range(len(shortSecSizes(z))):

        if q < cutPoints(z):
            indexVal = shortSecSizes(z)(q)
            docScore+= allSecScoreDicP1(tmpHeadSec(q))(indexVal)
            docScoreReducer *= allSecReducerDicP1(tmpHeadSec(q))(indexVal)
        else:
            indexVal = shortSecSizes(z)(q)
            docScore+= allSecScoreDicP2(tmpHeadSec(q))(indexVal)
            docScoreReducer *= allSecReducerDicP2(tmpHeadSec(q))(indexVal)
    docScore = docScore * docScoreReducer
    tmpvals.append(docScore)

I tried to change it to understand the list but it was slower:

        docScore = (sum((allSecScoreDicP1(tmpHeadSec(q))(shortSecSizes(z)(q)) if q < cutPoints(z) else allSecScoreDicP2(tmpHeadSec(q))(shortSecSizes(z)(q)) for q in range(len(shortSecSizes(z))))) for z in range(numTemps))
        docReducer = (np.prod((allSecReducerDicP1(tmpHeadSec(q))(shortSecSizes(z)(q)) if q < cutPoints(z) else allSecReducerDicP2(tmpHeadSec(q))(shortSecSizes(z)(q)) for q in range(len(shortSecSizes(z))))) for z in range(numTemps))
        tmpvals = (docScore(x) * docReducer(x) for x in range(len(docScore)))

Any suggestion on optimization methods would be greatly appreciated. I also tried to convert the code to cython, I snapped it and worked, but it was about 10 times slower!

dnd 5th – Are the Tiefling sub-races of the Mordenkainen Tome of Foes specific to a particular set of campaigns?

Are the Tiefling sub-races of Mordenkainen's Tome of Foes specific to a particular set of campaigns?

In Tome of Mordenkainen's Enemies (MTF) there is a section on Subraces Tiefling (p.21), which explains how the information about a Tiefling's ability score and hellish legacy in the player's manual relates to Asmodeus. Let's say "Default Tiefling" before MTF.

Under Subraces Tieflings, there are a variety of Subrace Traits for example Tieflings associated with Baalzebul or Fierna.

He says it's a DM option to include other Tiefling subraces, but I was wondering: Is it for a particular set of campaigns, or is it supposed to be a global change?

Google Analytics content group, should I use gtag set or gtag config?

I am trying to separate the pages of my site using "content group" in google analytics.
So that I can track the performance of the different page titles.
I don't know which of these two is the right way to modify the html code to follow each group.

Should i use what i see under admin > property > view > content grouping ?

gtag('set', {'content_group1': 'My Group Name'});

OR
what i see on https://support.google.com/analytics/answer/2853546?hl=en&utm_id=adcode

gtag('config', 'GA_TRACKING_ID', {'content_group1': 'My Group Name'});

saml – Sure of the valid parameter set, Powershell says: "The parameter set cannot be resolved …"

I am trying to run a Powershell cmdlet that accepts only one of the three specific parameters. I am sure that I know these parameters and that I enter these parameters correctly. I am running Powershell as an administrator and I am certain that the associated Powershell module is loaded and that the cmdlet I am trying is valid and loaded from this module.

The cmdlet is Set-ADFSRelyingPartyTrust -SamlResponseSignature and the valid parameters are MessageOnly AssertionOnly and MessageAndAssertion as provided by: https://docs.microsoft.com/en-us/powershell/module/adfs/set-adfsrelyingpartytrust?view=winserver2012r2-ps

The problem I get is that no matter which of the three I try, I get the error:

Set-AdfsRelyingPartyTrust : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Set-AdfsRelyingPartyTrust -SamlResponseSignature MessageAndAssertion
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) (Set-AdfsRelyingPartyTrust), ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.IdentityServer.Management.Commands.SetRelyingPartyTrustCommamd

Frustratingly, if I launch the cmdlet with a bad known parameter, with a -Whatif, it signals:

Set-AdfsRelyingPartyTrust : Cannot validate argument on parameter 'SamlResponseSignature'. The argument "False" does not belong to the set "AssertionOnly,MessageAndAssertion,MessageOnly" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

Even if I copy + paste a value from the reported set, I get the same error. What am i doing wrong?

I apologize if this has already been answered. All of the search results that I looked at only dealt with what to do if this error appears in the context of a larger script, or if the poster was unsure of it 39; valid parameter set. I did not find any discussion of this error when the cmdlet is run independently and the set of parameters is known.

Really long list inside a modal – set the height of the list and scroll it?

Yes, your idea sounds good.
Scroll.

I don't know if the practice of placing such a list in modal is appropriate.

Maybe the product search system should be redesigned and minimized to the minimum necessary for the user?

Also looking at the items on the list – maybe someone should create category architecture for them – using the Sorting cards (for example).
I mean there are a lot of items, which can be classified into energy (energy storage (…), – while in the energy there may be a category drums subcategory (level II) (battery chargers, battery accessories (…).

This approach gives a lot gives many possible long-term opportunities after the implementation (filtering – sorting by category etc.)

enter description of image here

T or F: the subset of a regular set on {a, b, c} consisting only of strings that do not use the symbol c is regular.

i think this is true. A subset of any regular set must always be recognized by certain DFAs, and is it therefore regular? Is it correct? I don't know if I understand the question. Thank you for any clarification.

set theory – What are the irreducible elements of join in the semi-network of finite dense binary relations?

Work with relationships in a purely theoretical way, i.e. as simple sets of ordered pairs, we see for any relationship $ R $ there is a minimal set of unique inclusion $ X $ such as $ R subseteq X times X $ that we can refer to as $ X = text {fld} (R) $. In addition we say any relationship $ L $ is isomorphic to $ R $ and write that $ R cong L $ if there is a bijection $ f: text {fld} (R) to text {fld} (L) $ such as $ forall x, y in text {fld} (R) left (xRy iff f (x) Lf (y) right) $. Now if we call a relationship $ R $ dense if and only if $ forall (a, b) in R existent v in text {fld} (R) 🙁 a, v), (v, b) in R $, is there a simple way to characterize finite dense relationships using other REL properties?

From the definition, we see if $ {R_i } _ {i in I} $ is an indexed family of dense relationships then $ K = bigcup_ {i in I} R_i $ must also be a dense relation, i.e. the REL property of being dense is closed under arbitrary unions. So I thought it would be logical to see if I could characterize all the isomorphism classes of the irreducible join (w.r.t $ cup $) dense binary relationships. Now I can show that if $ J $ is a joined, irreducible dense relationship (i.e., it is a dense relationship that is not a union of two or more distinct dense relationships) then the oriented graph $ D = ( text {fld} (J), J) $ must have vertices $ s, t in text {fld} (J) $ so that each vertex $ v $ in the digraph $ D $ is both accessible by $ s $ and can reach $ t $ (i.e. the digraph is bi-rooted). In fact, the first ones join irreducible dense relations (they are all those which have three elements of field or less):

$$ J_1 cong {(1,1) } $$
$$ J_2 cong {(1,2), (2,2) } $$
$$ J_3 cong {(1,1), (1,2) } $$
$$ J_4 cong {(1,3), (1,2), (2,3), (2,2) } $$
$$ J_5 cong {(1,2), (2,3), (3,1), (3,2), (1,3) } $$

That said, is there a finite number of dense, irreducible relationships (up to isomorphism)? If that's true, what are they? If not, can we still characterize them, or is there another simple way to characterize the REL property of being finite and dense?


Finally, it is not difficult to prove inequality:

$$ | R | leq | {(a, b) in R: (a, a) in R lor (b, b) in R } | + | {T subseteq R: T cong {(1,3), (3,2), (1,2) } | $$

As the corollary shows, there are no finite asymmetric dense relationships, because $ R $ asymmetric then the set on the left is empty while the one on the right has the size at most the number of sets of arc of triangle orientation in $ R $ which is at most the number of triangular graphs in the graph whose adjacency relation is equal to the symmetric closure of $ R $ which is strictly less than $ | R | $ so this is a contradiction.

algorithms – the largest set of sums without multiplicity

Given a group $ G $, the set of two sets $ A, B $ is noted as $ A + B = {a + b: a in A, b in B } $. We say $ A $ injects $ B $, if $ A + B $ has no multiplicities, that is to say $ | A + B | = | A || B | $. We leave $ I (B) = max {| A |: A text {injects} B } $ . For practically, let's say $ G $ is the whole modulo addition $ N $.

Given a set $ B $, can we determine $ I (B) $ in the time polynomial $ N $?

statistics – Median of a set with a special pattern

Suppose that $ a_i in mathbb {N}, ; forall i in {1,2, dots, n } $, and $ b in mathbb {N} $, and

$$ a_1 leq a_2 leq ldots leq a_n. $$

I want to find the median from the next set,

$$ A = {a_1-b, a_2-2b, ldots, a_n-nb }. $$

I already know two things,

  1. There are algorithms and methods to find the median of an unsorted array in more or less worse execution time than $ O (n) $. The easiest way is just to sort the whole thing and find the middle number in $ O (n log (n)) $.
  2. Together $ A $ is not monotonous.

Anyone have an idea to calculate the median of $ A $ in a faster way? (Like adding or subtracting or multiplying a certain number to certain elements of $ A $ and make it monotonous ?!)

set theory – Improve a Lindstrom-y fact on $ mathcal {L} _ { omega_1, omega} $?

See for example the last section of Ebbinghaus / Flum / Thomas for the relevant context on the theory of abstract models. Below, all languages ​​are finished for simplicity. "$ HC $"is the set of hereditarily countable sets.


There is a silly version of Lindstrom's theorem for infinite logic $ mathcal {L} _ { omega_1, omega} $ obtained by replacing the compactness with Barwise compactness:

$ (*) quad $ Assume that $ mathcal {L} = (Sent_ mathcal {L}, models_ mathcal {L}) $ is a regular logic such as:

  • $ Sent_ mathcal {L} subseteq HC $;

  • $ Sent _ { mathcal {L} _ { omega_1, omega}} subseteq Sent_ mathcal {L} $ and for each $ varphi in Sent _ { mathcal {L} _ { omega_1, omega}} $ we have $ Mod _ { mathcal {L} _ { omega_1, omega}} ( varphi) = Mod_ mathcal {L} ( varphi) $;

  • $ mathcal {L} $ to the descending Lowenheim-Skolem property for single sentences: if $ theta in Sent_ mathcal {L} $ has a model, then it has a countable model; and

  • $ mathcal {L} $ East Barwise compact: for each eligible countable $ mathbb {A} $ and all $ mathbb {A} $-this. theory $ mathfrak {T} subseteq mathcal {L} cap mathbb {A} $, if each $ mathbb {A} $– finished subset of $ mathfrak {T} $ then has a model $ mathfrak {T} $ has a model.

so $ equiv_ mathcal {L} $ coarse $ equiv ^ {EF} _ { omega_1} $: if Duplicator has a winning strategy in the game of length EF $ omega_1 $ Between $ mathcal {A} $ and $ mathcal {B} $, then $ mathcal {A} equiv_ mathcal {L} mathcal {B} $.

(Note that the above would be trivial if we restricted attention to countable structures, by Scott's isomorphism theorem.)

Now, it's sub-optimal in two different ways. The most obvious is that we don't get that. $ equiv_ mathcal {L} $ and $ equiv _ { omega_1, omega} $ coincide (since EF games do not characterize infinite equivalence well). However, the annoyance that I want to focus on is the "implementation specific" aspect: while some emphasis on implementation (the first point) is necessary to give a meaning to the compactness of Barwise as a property of abstract logic, the second point in my opinion in my opinion underlines the specific details of $ mathcal {L} $ too much.

Question: East $ (*) $ always true if we replace the second point $ (*) $ with "$ mathcal {L} ge mathcal {L} _ { omega_1, omega} $"- that is, if we simply require that for each $ varphi in Sent _ { mathcal {L} _ { omega_1, omega}} $ there are some $ psi in Sent_ mathcal {L} $ with $ Mod _ { mathcal {L} _ { omega_1, omega}} ( varphi) = Mod_ mathcal {L} ( psi) $?

In the next two sections, I outline the evidence of $ (*) $ and highlight the key obstacle.


To prove $ (*) $

assume $ mathcal {A} equiv _ { omega_1} ^ {EF} mathcal {B} $ But $ mathcal {A} models varphi $ and $ mathcal {B} models neg varphi $ for some people $ varphi in mathcal {L} $. Let $ varphi ^ A, varphi ^ B $ to be the relativizations of $ varphi $ to two new unary predicates, and let $ r $ to be a real coding of these sentences, $ mathcal {A} $, and $ mathcal {B} $. Inside $ mathbb {A} = L _ { omega_1 ^ {CK} (r)} (r) $ – which contains $ varphi ^ A $, $ varphi ^ B $, $ mathcal {A} $, and $ mathcal {B} $ since we can build a whole $ HC $ of real coding using $ Sigma_1 $– excursion – we consider the $ mathbb {A} $-this. theory $ mathfrak {T} subseteq mathcal {L} cap mathbb {A} $ describing the following type of structure:

  • The phrase "design" $ (D) $, which says that we have kinds $ A, B $ which describe structures with $ A models varphi $ and $ B models neg varphi $ and sort $ S $ and $ I $ or $ I $ is a linear order and $ S $ is a back-and-forth system of finite partial isomorphisms between $ A $ and $ B $ appropriately indexed by $ I $.

  • For each $ alpha < omega_1 ^ {CK} (r) $, the phrase "extension" $ (E) _ alpha $: "$ alpha $ integrates as an initial segment of $ I $. "

  • The sentence "object" $ (O) $: "$ I $ himself is a $ r $– calculable relation on $ omega $. "

The fact is that $ mathcal {A} $ and $ mathcal {B} $ obviously generate a model $ mathcal {M} $ of $ {(D) } cup {(E) _ alpha: alpha < omega_1 ^ {CK} (r) } $. It does not satisfy $ (O) $ of course but fixing $ alpha < omega_1 ^ {CK} $ we can "cut" the $ I $-part of $ mathcal {M} $ get a structure $ mathcal {M} _ alpha $ who only captures $ mathcal {A} equiv ^ {EF} _ alpha mathcal {B} $ but that is an element of $ mathbb {A} $ – It’s, $ mathcal {M} _ alpha models {(D), (O) } cup {(E) _ beta: beta < alpha } $.

The compactness of Barwise then gives us a model of the whole theory $ mathfrak {T} $. From this in turn, we get a structure with a $ A $– satisfactory part $ varphi $, a $ B $– satisfactory part $ neg varphi $, And one $ omega ^ * $-indexed back-and-forth system of finite partial isomorphisms between them. This whole situation is described by a single $ mathcal {L} $-phrasing $ theta $and so we get a countable model of $ theta $; but then the $ A $– and $ B $-the pieces of this model are isomorphic, contradicting their $ mathcal {L} $-inéquivalence.


L & # 39; hurdle

So what breaks down if we try to execute the argument above to prove the most hoped for result?

Well ignoring $ (D) $ and the "one-and-done" requirements that true coding $ varphi ^ A, varphi ^ B, mathcal {A}, mathcal {B} $ to be in $ mathbb {A} $, the first thing we needed was $ mathbb {A} $ contain the sentences $ (E) _ alpha $ for each $ alpha < mathbb {A} cap Ord $. When the $ mathcal {L} _ { omega_1, omega} $-the sentences appear in $ mathcal {L} $ to the second unwanted second bullet above, it's trivial; but if the incorporation $ mathcal {L} _ { omega_1, omega} le mathcal {L} $ is weird enough we might need to build this $ mathbb {A} $ as a great union of allowable sets to "catch our tail". It is doable …

… but that ruins the second requirement, that we have to be able to get something like $ (O) $. Basically we need a $ mathcal {L} $-phrasing (or at least one $ mathbb {A} $-this. $ mathcal {L} $-theory) who only describes things $ mathbb {A} $ But Is describe type orders of arbitrarily large order type $ < mathbb {A} cap Ord $. It’s a sense in which $ mathbb {A} $ should be "similar to" $ L _ { omega_1 ^ {CK}} $"… which we would have no reason to expect here.

In other words, the only admissible sets large enough to have their fragments of $ mathcal {L} $ talk about all the ordinals smaller than their size might be too big to do something like the $ (O) $-trick above. But $ (O) $ was crucial: it was the only way to conclude that after applying the compactness of Barwise, we would get something whose back-and-forth indexer was ill-founded.